import urllib2 import json # Look up POP in near Future 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) all= parsed_json['forecast']['txt_forecast']['forecastday'] period_0 = parsed_json['forecast']['txt_forecast']['forecastday'][0]['title'] period_1 = parsed_json['forecast']['txt_forecast']['forecastday'][1]['title'] Outlook_0= parsed_json['forecast']['txt_forecast']['forecastday'][0]['fcttext_metric'] Outlook_1= parsed_json['forecast']['txt_forecast']['forecastday'][1]['fcttext_metric'] pop_0= parsed_json['forecast']['txt_forecast']['forecastday'][0]['pop'] pop_1= parsed_json['forecast']['txt_forecast']['forecastday'][1]['pop'] print period_0 print pop_0 print Outlook_0 print period_1 print pop_1 print Outlook_1 if int(pop_0) <=25 or int(pop_1) <=25 : print ("Less than 25% chance of rain") else: print ("Decent chance of rain.") #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