import urllib2 import json f = urllib2.urlopen('http://api.wunderground.com/api/003508f51f58d4f4/geolookup/forecast/q/WI/Black_Earth.json') json_string = f.read() parsed_json = json.loads(json_string) x=int(raw_input("What period for weather forcast? (0-7)")) all= parsed_json['forecast']['txt_forecast']['forecastday'] period = parsed_json['forecast']['txt_forecast']['forecastday'][x]['title'] Outlook= parsed_json['forecast']['txt_forecast']['forecastday'][x]['fcttext_metric'] pop= parsed_json['forecast']['txt_forecast']['forecastday'][x]['pop'] pop_1= parsed_json['forecast']['txt_forecast']['forecastday'][x+1]['pop'] print period print Outlook print period+" " +"Chance of percipitation is: "+pop + "%" if int(pop) ==0: print ("It's not going to rain") else: print (" It might rain or snow") print"Chance of percipitation next period is: "+pop_1 + "%" for period in all: print period['title'] print period['fcttext_metric'] #location = parsed_json['location']['city'] #temp_f = parsed_json['current_observation']['temp_f'] #print "Current temperature in %s is: %s" % (location, temp_f)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question