Read the statement by Michael Teeuw here.
save some information from a xml or json to a txt file
-
Hi, thank you for the code. But there was a little misstake I think. I have copied your code and save. put in my api and the right folder.
then the first try. All works fine the code generate a test.txt file. But then I oen the txt file it was empty.
Ok I think maybe I put in something wrong. But everything was ok.At a second try I chnage the folder name, because I think maybe the was some folder Rights or something else. But the same. The txt file was empty.
At my next try I cut of the f.write line and there was only written f.write(‘Today is’)
And I see everything work like it should. In the txt file was written Today is. Now I put some more in this line again. Everything works fine till I put the word weather. If I put this the txt file will be empty.I like to try something mor later today. But I want give you a feedback. And I like to say thank you.
greets gismo
-
Sorry I forgett there was no error. Also Python displays no error if I try it a the Python IDLE.
-
@gismo2006 I think I got the problem. The german description can contain letters like äöü etc. i will fix that later when i’m at home.
-
Now it should work
#!/usr/bin/python # -*- coding: utf-8 -*- import codecs import json import subprocess APP_ID = '' FILE_PATH = 'test.txt' url = 'http://api.openweathermap.org/data/2.5/weather?id=2934486&lang=de&units=metric&mode=json&appid=' + APP_ID curl_req = 'curl -L ' + '"' + url + '"' p = subprocess.Popen(curl_req, stdout=subprocess.PIPE, shell=True) (output, err) = p.communicate() p_status = p.wait() try: decoded = json.loads(output) weather = decoded['weather'][0]['description'] temp = decoded['main']['temp'] f = codecs.open(FILE_PATH,'w', 'utf-8') f.write('Today is ' + weather + ' and ' + str(temp) + ' degrees.') f.close() except (ValueError, KeyError, TypeError): pass
-
Hi, a big thank you!!
Its work perfect!!!
Many Thanks! :-)
greets gismo
-
Welcome :)
-
@LukeCodewalker i want to make the same Module for Switzerland but i don`t know how to find the json data for my region…
Can you help me please? ;) I found your link in the node_helper.js file. From where do you got that?
I would like o work with http://alarm.meteocentrale.ch/
-
@Squirrel
i did some reverse engineering of the dwd-website and found this json file.
i had a short look at your link and did not found something similar there. do you know if theres an app for ios where the data is shown? maybe i can help you then. -
-
@LukeCodewalker Thx for the answer. I will try it out. At the moment i can`t find my City. But maybe only because there is no warning at the moment? Otherwise on the alarm.meteocentrale.ch is still a warning for snow on the streets…?
What about wetteralarm.ch/? This is a app for iPhone and Android! Maybe it can work with this site?