json - How to put weather underground forecast icons -
i´m new program python , trying put icons weather underground forecast, in line labelimg1 don´t show icon , dont give error. can helpme.
i put here part of code. in advance.
url = "http://api.wunderground.com/api/xxxxxxxxx/forecast/q/pt/lisbon.json"
temp = urllib.request.urlopen(url) json_string = temp.read().decode('utf-8') parsed_json = json.loads(json_string) high = parsed_json['forecast']['simpleforecast']['forecastday'][0]['high']['celsius'] low = parsed_json['forecast']['simpleforecast']['forecastday'][0]['low']['celsius'] con = parsed_json['forecast']['simpleforecast']['forecastday'][0]['conditions'] day = parsed_json['forecast']['simpleforecast']['forecastday'][0]['date']['day'] high1 = parsed_json['forecast']['simpleforecast']['forecastday'][1]['high']['celsius'] low1 = parsed_json['forecast']['simpleforecast']['forecastday'][1]['low']['celsius'] con1 = parsed_json['forecast']['simpleforecast']['forecastday'][1]['conditions'] day1 = parsed_json['forecast']['simpleforecast']['forecastday'][1]['date']['day'] **icon = parsed_json['forecast']['simpleforecast']['forecastday'][0]['icon']** **img7 = photoimage(icon)** img8 = photoimage(file='c:/house/png/clear.png') **labelimg1 = label(self, image=img7)** labelimg2 = label(self, image=img8) label1 = label(self, text="dia: %s , céu: %s" % (day, con,), font="arial 12 bold") label2 = label(self, text="temperatura miníma de: %sº - temperatura máxima de: %sº " % (low, high,), font="arial 12 bold") label3 = label(self, text="dia: %s , céu: %s " % (day1, con1,), font="arial 12 bold") label4 = label(self, text="temperatura miníma de: %sº - temperatura máxima de: %sº " % (low1, high1,), font="arial 12 bold") label1.pack(pady=15) **labelimg1.image = img7 labelimg1.pack()** label2.pack() label3.pack(pady=20) labelimg2.image = img8 labelimg2.pack() label4.pack() temp.close()
parsed_json["current_observation"]["icon_url"]
returns current weather icon of location.
more specific:
>>> import urllib >>> import json >>> url = "https://api.wunderground.com/api/<your api key>/geolookup/conditions/q/<your location>.json" >>> temp = urllib.request.urlopen(url) >>> json_string = temp.read().decode('utf-8') >>> parsed_json = json.loads(json_string) >>> parsed_json["current_observation"]["icon_url"] 'http://icons.wxug.com/i/c/k/nt_clear.gif'
Comments
Post a Comment