import json import urllib2 def main(eQuake): eQuake = "urlData" urlData = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojson" webUrl = urllib2.urlopen(urlData) print webUrl.getcode() # answer 200 If (webUrl.getcode() == 200): dataRead = webUrl.read() print dataRead else print "Received and error from server, cannot retrieve results" + str (webUrl.getcode()) def printresults(dataRead): theJson = json.loads(dataRead) if "title" in theJson["metaData"]: print theJson["metadata"]["title"] # USGS Magnitude 2.5 + Earthquakes. Past Day count = theJson["metadata"]["count"]; print str(count) + "events recorded" # answer 23 events recorded
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