Wetter mit Open Weather Map API in Python
Ich habe die Aufgabe geteilt:
Ein eigenständiges Modul liest die Daten von openweather und schriebt dies in eine JSON Datei.
Der server liest diese Datei und wandelt Formate um.
Der Client kann jede Sekunde den Status abfragen.
Da sich unser Wetter sich aber (noch nicht) so schnell ändert, reicht es, das Wetter jede viertel Stunde zu holen.
Den Client über crontab starten
# examle below will be excecuted every 15 minutes
# */15 * * * * python /home/pi/433/openweather_client.py Berlin > crontab_ow_client.log 2>&1
Client
download: openweather_client (besser die Datei herunterladen, da mit copy und paste man evtl. die berüchtigten “indentation” Probleme bekommt).
Update: api key eingefügt – wie im Kommentar unten beschrieben. Vielen Dank Christoph.
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# client for openweather API
# - call PAI
# - translate fields if required
# - save JSON format in a file
# add this programm to crontab: crontab -e
# examle below will be excecuted every 15 minutes
# */15 * * * * python /home/pi/433/openweather_client.py Berlin > crontab_ow_client.log 2>&1
# 2013-06-23 V0.1 by Thomas Hoeser
#
import urllib2, json, sys, pprint, argparse
verbose_level = 0
debug_level = 0
#---------------------------------------------------------------------------------------------
if __name__ == "__main__":
pp = pprint.PrettyPrinter(indent=4)
parser = argparse.ArgumentParser(description='open weather client by Thomas Hoeser / 2013')
parser.add_argument("-v", "--verbose", default=False,
dest='verbose', help="increase output verbosity", type=int)
parser.add_argument("-d", "--debug", action='store_const', dest='debug',
const='value-to-store', help="debug mode - will prevent executing send command or reading 1-wire sensor")
parser.add_argument('--version', action='version', version='%(prog)s 0.2')
parser.add_argument("city")
args = parser.parse_args()
if args.verbose : verbose_level = args.verbose
if args.debug : debug_level = 1
ow_city = args.city # set your city from command line
ow_country = "de"
ow_url_api = "http://api.openweathermap.org/data/2.5/"
ow_url_cur = ow_url_api + "weather?q=" + ow_city + "," + ow_country
ow_url_fcst = ow_url_api + "forecast?q=" + ow_city + "," + ow_country
ow_city = ow_city.lower()
ow_file_cur = "ow_" + ow_city + "_cur.json"
ow_file_for = "ow_" + ow_city + "_for.json"
# file_cur = open(ow_file_cur, 'w')
# file_for = open(ow_file_for, 'w')
print "--------------------- GET CURRENT DATA"
if verbose_level > 1:
print "# fetchHTML(): "
print ow_url_cur
try:
print "URL - Request",
req = urllib2.Request(ow_url_cur)
print " - Open",
response = urllib2.urlopen(req)
print " - Read Response"
output_cur = response.read()
#output = fetchHTML(ow_url_cur)
json_out_cur = json.loads(output_cur)
# print json_out_cur
if verbose_level > 2: pp.pprint(json_out_cur)
except:
print "Panic: cannot read url:", ow_url_cur
print "--------------------- GET FORECAST DATA"
if verbose_level > 1:
print "# fetchHTML(): "
print ow_url_fcst
try:
print "URL - Request",
req = urllib2.Request(ow_url_fcst)
print " - Open",
response = urllib2.urlopen(req)
print " - Read Response"
output_fcst = response.read()
json_out_fcst = json.loads(output_fcst)
# print json_out_cur
if verbose_level > 2: pp.pprint(json_out_fcst)
except:
print "Panic: cannot read url:", ow_url_cur
print "dump json"
with open(ow_file_cur, 'w') as outfile:
json.dump(json_out_cur, outfile)
with open(ow_file_for, 'w') as outfile:
json.dump(json_out_fcst, outfile)
Mit folgendem Program kann man die JSON Datei überprüfen.
Dort ist auch die Datenstruktur der openweather API sichtbar,
Test-Script
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Read openweather JSON file
# 2013-06-29 V0.3 by Thomas Hoeser
#
import urllib2, json, sys, pprint, argparse
from time import strftime
from datetime import datetime
verbose_level = 0
debug_level = 0
#---------------------------------------------------------------------------------------------
ow_dict_example = {
u'base': u'global stations',
u'clouds': { u'all': 75}, # Cloudiness in %
u'cod': 200,
u'coord': { u'lat': 50.950001, u'lon': 7.53333}, # City location
u'dt': 1371876600, # Time of data receiving in unixtime GMT
u'id': 2809517,
u'main': { u'humidity': 77, # Humidity in %
u'pressure': 1016, # Atmospheric pressure in hPa
u'temp': 287.69, # Temperature in Kelvin. Subtracted 273.15 from this figure to convert to Celsius.
u'temp_max': 289.15, # Minimum and maximum temperature
u'temp_min': 287.04},
u'name': u'Wiehl', # City name
u'rain': { u'3h': 0.5}, # Precipitation volume mm per 3 hours
u'sys': { u'country': u'DE', u'sunrise': 1371870953, u'sunset': 1371930488},
# see http://bugs.openweathermap.org/projects/api/wiki/Weather_Condition_Codes
u'weather': [ { u'description': u'broken clouds',
u'icon': u'04d', # icon no - e.g. : 04d.png = broken clouds
u'id': 803, # Weather Condition Codes - e.g. 803 = broken clouds
u'main': u'Clouds'}],
u'wind': { u'deg': 170, # Wind direction in degrees (meteorological)
u'speed': 3.6} # Wind speed in mps
}
#---------------------------------------------------------------------------------------------
def temp_k2c(temp_k):
temp_c = round(temp_k - 273.15,1)
return(temp_c)
#---------------------------------------------------------------------------------------------
def speed_mps2ms(speed_mps):
speed_ms = round(speed_mps * 0.44704,1)
return(speed_ms)
#---------------------------------------------------------------------------------------------
def wind_deg2txt(deg):
# 0 1 2 3 4 5 6 7 8
wind_dir_name = ['N','NO','O','SO','S','SW','W','NW','N']
wind_sections = 360 / 8
offset = wind_sections / 2
# range(start, stop[, step])
y = int( (deg + offset) / wind_sections )
if verbose_level > 3 :print deg, y, offset, wind_sections,
wind_dir_txt = wind_dir_name[y]
if verbose_level > 3 :print " -> " + wind_dir_txt
return(wind_dir_txt)
#---------------------------------------------------------------------------------------------
if __name__ == "__main__":
pp = pprint.PrettyPrinter(indent=4)
parser = argparse.ArgumentParser(description='open weather client by Thomas Hoeser / 2013')
parser.add_argument("-v", "--verbose", default=False,
dest='verbose', help="increase output verbosity", type=int)
parser.add_argument("-d", "--debug", action='store_const', dest='debug',
const='value-to-store', help="debug mode - will prevent executing send command or reading 1-wire sensor")
parser.add_argument('--version', action='version', version='%(prog)s 0.2')
parser.add_argument("city")
args = parser.parse_args()
if args.verbose : verbose_level = args.verbose
if args.debug : debug_level = 1
ow_city = args.city # set your city from command line
ow_city = ow_city.lower()
ow_file_cur = "/home/pi/ow_" + ow_city + "_cur.json"
ow_file_for = "/home/pi/ow_" + ow_city + "_for.json"
ow_file_for7= "/home/pi/ow_" + ow_city + "_for7.json"
# ----------------------------------------------------------------------------------------
print "------------------------- Aktuell"
if verbose_level > 0 :
print "open JSON file: ", ow_file_cur
try:
with open(ow_file_cur, 'r') as json_file:
json_out_cur = json.load(json_file)
except:
print "PANIC: cannot open file: " + ow_file_cur
sys.exit(1)
if verbose_level > 1 :
pp.pprint(json_out_cur)
print "Stadt : " + str(json_out_cur['name'])
print "ID : " + str(json_out_cur['id'])
status = datetime.fromtimestamp(json_out_cur['dt']).strftime('%Y-%m-%d %H:%M')
print "Stand : " + status
print "Windrichtung: " + str(json_out_cur['wind']['deg']) + " Grad"
wind_speed = json_out_cur['wind']['speed']
wind_speed = speed_mps2ms(wind_speed)
print "Windgeschw. : " + str(wind_speed) + " m/s"
print "Wolken : " + str(json_out_cur['clouds']['all']) + "%"
print "Himmel : " + str(json_out_cur['weather'][0]['description']) + ""
print "owIcon : " + str(json_out_cur['weather'][0]['icon']) + ""
print "owID : " + str(json_out_cur['weather'][0]['id']) + ""
print "Feuchte : " + str(json_out_cur['main']['humidity']) + "%"
print "Druck : " + str(json_out_cur['main']['pressure']) + " hPa"
# print "Regen : " + str(json_out_cur['rain']['3h']) + " mm / 3 Stunden"
aufgang = datetime.fromtimestamp(json_out_cur['sys']['sunrise']).strftime('%H:%M')
print "S.Aufgang : " + aufgang
aufgang = datetime.fromtimestamp(json_out_cur['sys']['sunset']).strftime('%H:%M')
print "S.Untergang : " + aufgang
# temperature is measured in degree Kelvin unit
# get current temperature
temp_cur_c = temp_k2c ( json_out_cur['main']['temp'] )
print "Temp. : " + str(temp_cur_c) + " Grad"
temp_min_c = temp_k2c ( json_out_cur['main']['temp_min'] )
print "Temp.min : " + str(temp_min_c) + " Grad"
temp_max_c = temp_k2c ( json_out_cur['main']['temp_max'] )
print "Temp.max : " + str(temp_max_c) + " Grad"
# ----------------------------------------------------------------------------------------
print "\n------------------------- Vorhersage - 3 Tage / 3h"
if verbose_level > 0 :
print "open JSON file: ", ow_file_for
try:
with open(ow_file_for, 'r') as json_file:
json_out_for = json.load(json_file)
except:
print "PANIC: cannot open file: " + ow_file_for
sys.exit(1)
if verbose_level > 1 :
pp.pprint(json_out_for)
print "Stadt : " + str(json_out_for['city']['name'])
print "Einträge : " + str(json_out_for['cnt'])
count = json_out_for['cnt']
# 2013-06-28 18:00:00 12.6 Grad 11.6 Grad 12.6 Grad
print "Zeit Temp Temp.min Temp.max"
for x in range(1,count):
cur_stamp = json_out_for['list'][x]['dt_txt']
cur_date = cur_stamp[0:10]
cur_hour = cur_stamp[11:13]
#print cur_date, cur_hour
print "" + str(json_out_for['list'][x]['dt_txt']) + "",
temp_cur_c = temp_k2c ( json_out_for['list'][x]['main']['temp'] )
print " " + str(temp_cur_c) + " Grad",
temp_min_c = temp_k2c ( json_out_for['list'][x]['main']['temp_min'] )
print " " + str(temp_min_c) + " Grad",
temp_max_c = temp_k2c ( json_out_for['list'][x]['main']['temp_max'] )
print " " + str(temp_max_c) + " Grad",
print " " + str(json_out_for['list'][x]['main']['humidity']) + "%",
print " " + str(int(json_out_for['list'][x]['main']['pressure'])) + " hPa",
print " " + str(int(json_out_for['list'][x]['wind']['deg'])) + " Grad",
wind_richtung = wind_deg2txt(json_out_for['list'][x]['wind']['deg'])
print " " + wind_richtung + "",
wind_speed = json_out_for['list'][x]['wind']['speed']
wind_speed = speed_mps2ms(wind_speed)
print " " + str(wind_speed) + " m/s",
print " " + str(json_out_for['list'][x]['clouds']['all']) + " %",
print " " + str(json_out_for['list'][x]['weather'][0]['icon']) + "",
print " " + str(json_out_for['list'][x]['weather'][0]['id']) + "",
print " " + str(json_out_for['list'][x]['weather'][0]['main']) + "",
print " " + str(json_out_for['list'][x]['weather'][0]['description']) + "",
print
# ----------------------------------------------------------------------------------------
print "\n------------------------- Vorhersage - 7 Tage"
if verbose_level > 0 :
print "open JSON file: ", ow_file_for7
try:
with open(ow_file_for7, 'r') as json_file:
json_out_for = json.load(json_file)
except:
print "PANIC: cannot open file: " + ow_file_for7
sys.exit(1)
if verbose_level > 1 :
pp.pprint(json_out_for)
print "Stadt : " + str(json_out_for['city']['name'])
status = datetime.fromtimestamp(json_out_cur['dt']).strftime('%Y-%m-%d %H:%M')
print "Stand : " + status
print "Einträge : " + str(json_out_for['cnt'])
count = json_out_for['cnt']
# 2013-06-28 18:00:00 12.6 Grad 11.6 Grad 12.6 Grad
print "Tag T-Mor T-tag T-Abn T-Ncht T-Max T-min Feucht Druck WindG WindR WindG Wolken Icon ID Wetter"
for x in range(1,count):
print "Tag-" + str(x),
temp_x = temp_k2c ( json_out_for['list'][x]['temp']['morn'] )
print " " + str(temp_x) + " Grad",
temp_x = temp_k2c ( json_out_for['list'][x]['temp']['day'] )
print " " + str(temp_x) + " Grad",
temp_x = temp_k2c ( json_out_for['list'][x]['temp']['eve'] )
print " " + str(temp_x) + " Grad",
temp_x = temp_k2c ( json_out_for['list'][x]['temp']['night'] )
print " " + str(temp_x) + " Grad",
temp_x = temp_k2c ( json_out_for['list'][x]['temp']['max'] )
print " " + str(temp_x) + " Grad",
temp_x = temp_k2c ( json_out_for['list'][x]['temp']['min'] )
print " " + str(temp_x) + " Grad",
print " " + str(json_out_for['list'][x]['humidity']) + "%",
print " " + str(int(json_out_for['list'][x]['pressure'])) + " hPa",
print " " + str(int(json_out_for['list'][x]['deg'])) + " Grad",
wind_richtung = wind_deg2txt(json_out_for['list'][x]['deg'])
print " " + wind_richtung + "",
wind_speed = json_out_for['list'][x]['speed']
wind_speed = speed_mps2ms(wind_speed)
print " " + str(wind_speed) + " m/s",
print " " + str(json_out_for['list'][x]['clouds']) + " %",
print " " + str(json_out_for['list'][x]['weather'][0]['icon']) + "",
print " " + str(json_out_for['list'][x]['weather'][0]['id']) + "",
print " " + str(json_out_for['list'][x]['weather'][0]['main']) + "",
print " " + str(json_out_for['list'][x]['weather'][0]['description']) + "",
print
So sieht dann die Ausgabe aus:
pi@raspberrypi ~/bin $ openweather_read.py Wiehl
------------------------- Aktuell
Stadt : Wiehl
ID : 2809517
Stand : 2013-06-29 17:02
Windrichtung: 340 Grad
Windgeschw. : 2.1 m/s
Wolken : 75%
Himmel : broken clouds
owIcon : 04d
owID : 803
Feuchte : 67%
Druck : 1020 hPa
S.Aufgang : 05:19
S.Untergang : 21:47
Temp. : 16.4 Grad
Temp.min : 15.0 Grad
Temp.max : 17.2 Grad
------------------------- Vorhersage - 3 Tage / 3h
Stadt : Wiehl
Einträge : 41
Zeit Temp Temp.min Temp.max
2013-06-29 18:00:00 14.1 Grad 12.3 Grad 14.1 Grad 87% 991 hPa 325 Grad NW 2.2 m/s 92 % 04d 804 Clouds overcast clouds
2013-06-29 21:00:00 11.9 Grad 10.2 Grad 11.9 Grad 90% 993 hPa 326 Grad NW 1.5 m/s 68 % 04n 803 Clouds broken clouds
2013-06-30 00:00:00 11.1 Grad 9.5 Grad 11.1 Grad 92% 994 hPa 302 Grad NW 1.0 m/s 92 % 04n 804 Clouds overcast clouds
2013-06-30 03:00:00 10.4 Grad 8.9 Grad 10.4 Grad 97% 993 hPa 279 Grad W 0.9 m/s 64 % 04n 803 Clouds broken clouds
2013-06-30 06:00:00 11.0 Grad 9.6 Grad 11.0 Grad 98% 993 hPa 271 Grad W 1.3 m/s 44 % 03d 802 Clouds scattered clouds
2013-06-30 09:00:00 14.2 Grad 12.9 Grad 14.2 Grad 95% 993 hPa 277 Grad W 1.4 m/s 20 % 02d 801 Clouds few clouds
2013-06-30 12:00:00 15.1 Grad 13.9 Grad 15.1 Grad 91% 992 hPa 266 Grad W 1.6 m/s 68 % 10d 500 Rain light rain
2013-06-30 15:00:00 16.2 Grad 15.1 Grad 16.2 Grad 88% 991 hPa 266 Grad W 1.8 m/s 92 % 04d 804 Clouds overcast clouds
2013-06-30 18:00:00 16.4 Grad 15.4 Grad 16.4 Grad 90% 990 hPa 274 Grad W 1.4 m/s 92 % 04d 804 Clouds overcast clouds
2013-06-30 21:00:00 15.4 Grad 14.5 Grad 15.4 Grad 96% 990 hPa 250 Grad W 1.1 m/s 92 % 04n 804 Clouds overcast clouds
2013-07-01 00:00:00 14.9 Grad 14.0 Grad 14.9 Grad 98% 989 hPa 221 Grad SW 1.0 m/s 92 % 10n 500 Rain light rain
2013-07-01 03:00:00 14.2 Grad 13.4 Grad 14.2 Grad 98% 988 hPa 239 Grad SW 1.3 m/s 32 % 10n 500 Rain light rain
2013-07-01 06:00:00 15.2 Grad 14.5 Grad 15.2 Grad 99% 987 hPa 224 Grad SW 1.3 m/s 80 % 04d 803 Clouds broken clouds
2013-07-01 09:00:00 17.9 Grad 17.3 Grad 17.9 Grad 93% 986 hPa 237 Grad SW 1.9 m/s 32 % 03d 802 Clouds scattered clouds
2013-07-01 12:00:00 19.5 Grad 19.0 Grad 19.5 Grad 83% 985 hPa 251 Grad W 2.1 m/s 32 % 03d 802 Clouds scattered clouds
2013-07-01 15:00:00 19.0 Grad 18.6 Grad 19.0 Grad 73% 984 hPa 253 Grad W 2.1 m/s 88 % 04d 804 Clouds overcast clouds
2013-07-01 18:00:00 17.5 Grad 17.2 Grad 17.5 Grad 71% 984 hPa 249 Grad W 1.9 m/s 24 % 02d 801 Clouds few clouds
2013-07-01 21:00:00 14.4 Grad 14.2 Grad 14.4 Grad 87% 984 hPa 282 Grad W 1.6 m/s 68 % 04n 803 Clouds broken clouds
2013-07-02 00:00:00 12.6 Grad 12.5 Grad 12.6 Grad 90% 984 hPa 263 Grad W 1.1 m/s 64 % 04n 803 Clouds broken clouds
2013-07-02 03:00:00 11.0 Grad 11.0 Grad 11.0 Grad 87% 983 hPa 246 Grad SW 1.0 m/s 68 % 04n 803 Clouds broken clouds
2013-07-02 06:00:00 11.9 Grad 11.9 Grad 11.9 Grad 87% 983 hPa 232 Grad SW 1.1 m/s 80 % 04d 803 Clouds broken clouds
2013-07-02 09:00:00 14.8 Grad 14.8 Grad 14.8 Grad 85% 982 hPa 226 Grad SW 1.5 m/s 68 % 04d 803 Clouds broken clouds
2013-07-02 12:00:00 17.2 Grad 17.2 Grad 17.2 Grad 78% 981 hPa 248 Grad W 1.9 m/s 48 % 03d 802 Clouds scattered clouds
2013-07-02 15:00:00 17.4 Grad 17.4 Grad 17.4 Grad 72% 980 hPa 247 Grad SW 1.5 m/s 64 % 04d 803 Clouds broken clouds
2013-07-02 18:00:00 17.1 Grad 17.1 Grad 17.1 Grad 74% 979 hPa 216 Grad SW 0.8 m/s 68 % 04d 803 Clouds broken clouds
2013-07-02 21:00:00 14.9 Grad 14.9 Grad 14.9 Grad 68% 977 hPa 153 Grad SO 1.1 m/s 92 % 04n 804 Clouds overcast clouds
2013-07-03 00:00:00 13.0 Grad 13.0 Grad 13.0 Grad 96% 976 hPa 175 Grad S 1.2 m/s 92 % 10n 500 Rain light rain
2013-07-03 03:00:00 12.4 Grad 12.4 Grad 12.4 Grad 100% 976 hPa 233 Grad SW 2.5 m/s 92 % 10n 500 Rain light rain
2013-07-03 06:00:00 12.1 Grad 12.1 Grad 12.1 Grad 100% 977 hPa 243 Grad SW 2.3 m/s 92 % 10d 500 Rain light rain
2013-07-03 09:00:00 12.6 Grad 12.6 Grad 12.6 Grad 100% 978 hPa 248 Grad W 2.0 m/s 92 % 04d 804 Clouds overcast clouds
2013-07-03 12:00:00 14.3 Grad 14.3 Grad 14.3 Grad 98% 979 hPa 230 Grad SW 1.9 m/s 92 % 10d 500 Rain light rain
2013-07-03 15:00:00 15.1 Grad 15.1 Grad 15.1 Grad 97% 980 hPa 246 Grad SW 1.9 m/s 92 % 04d 804 Clouds overcast clouds
2013-07-03 18:00:00 15.4 Grad 15.4 Grad 15.4 Grad 99% 981 hPa 252 Grad W 2.0 m/s 92 % 04d 804 Clouds overcast clouds
2013-07-03 21:00:00 14.7 Grad 14.7 Grad 14.7 Grad 98% 983 hPa 256 Grad W 1.9 m/s 92 % 10n 500 Rain light rain
2013-07-04 00:00:00 13.7 Grad 13.7 Grad 13.7 Grad 98% 984 hPa 257 Grad W 1.9 m/s 92 % 04n 804 Clouds overcast clouds
2013-07-04 03:00:00 12.4 Grad 12.4 Grad 12.4 Grad 98% 985 hPa 253 Grad W 1.5 m/s 92 % 04n 804 Clouds overcast clouds
2013-07-04 06:00:00 12.7 Grad 12.7 Grad 12.7 Grad 98% 987 hPa 248 Grad W 1.4 m/s 88 % 04d 804 Clouds overcast clouds
2013-07-04 09:00:00 16.3 Grad 16.3 Grad 16.3 Grad 98% 988 hPa 229 Grad SW 1.5 m/s 20 % 02d 801 Clouds few clouds
2013-07-04 12:00:00 19.4 Grad 19.4 Grad 19.4 Grad 92% 988 hPa 227 Grad SW 1.8 m/s 8 % 02d 800 Clear sky is clear
2013-07-04 15:00:00 21.4 Grad 21.4 Grad 21.4 Grad 80% 988 hPa 239 Grad SW 1.8 m/s 0 % 01d 800 Clear sky is clear
------------------------- Vorhersage - 7 Tage
Stadt : Wiehl
Stand : 2013-06-29 17:02
Einträge : 7
Tag T-Mor T-tag T-Abn T-Ncht T-Max T-min Feucht Druck WindG WindR WindG Wolken Icon ID Wetter
Tag-1 11.3 Grad 15.3 Grad 16.6 Grad 15.1 Grad 16.6 Grad 11.3 Grad 91% 992 hPa 266 Grad W 1.6 m/s 68 % 10d 500 Rain light rain
Tag-2 15.3 Grad 19.6 Grad 17.5 Grad 12.6 Grad 19.6 Grad 12.6 Grad 83% 985 hPa 251 Grad W 2.1 m/s 32 % 03d 802 Clouds scattered clouds
Tag-3 11.9 Grad 17.2 Grad 17.1 Grad 13.0 Grad 17.4 Grad 11.9 Grad 78% 981 hPa 248 Grad W 1.9 m/s 48 % 10d 500 Rain light rain
Tag-4 12.1 Grad 14.3 Grad 15.4 Grad 13.7 Grad 15.4 Grad 12.1 Grad 98% 979 hPa 230 Grad SW 1.9 m/s 92 % 10d 501 Rain moderate rain
Tag-5 12.7 Grad 19.4 Grad 20.9 Grad 16.9 Grad 21.4 Grad 12.7 Grad 92% 988 hPa 228 Grad SW 1.8 m/s 8 % 02d 800 Clear sky is clear
Tag-6 12.6 Grad 17.2 Grad 17.8 Grad 12.8 Grad 17.8 Grad 12.6 Grad 0% 1003 hPa 351 Grad N 1.0 m/s 20 % 10d 500 Rain light rain
openweathermap verlangt inzwischen bei der Abfrage einen API-Key. somit hab ich folgende Zeile eingefügt :
ow_appid = ” your api-key” //muss man bei openweathermap generien es reicht der kostenlose!
und die folgenden verändert:
ow_url_cur = ow_url_api + “weather?q=” + ow_city + “,” + ow_country + “&appid=” + ow_appid
ow_url_fcst = ow_url_api + “forecast?q=” + ow_city + “,”+ ow_country + “&appid=” + ow_appid
des weiteren hat python noch ein paar identationen bemängelt, die ich korrigiert habe.
Welche Raspberry Pi Version hast du verwendet?
Das 1 script openweather_client.py habe ich jetzt auf zwei Versionen laufen lassen – funktioniert auf beiden Versionen:
cat /etc/os-release
PRETTY_NAME=”Raspbian GNU/Linux 7 (wheezy)”
PRETTY_NAME=”Raspbian GNU/Linux 8 (jessie)”