Last active
March 13, 2017 12:56
-
-
Save davepape/13b6d97250d89bd216c4 to your computer and use it in GitHub Desktop.
parse USGS's GeoJSON data of earthquakes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| import datetime | |
| import urllib2 | |
| # To read a locally saved file: | |
| # file = open('quakes.json') | |
| # Or, to read the latest data straight from the web: | |
| file = urllib2.urlopen('http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojson') | |
| text = file.read() | |
| data = json.loads(text) | |
| for quake in data['features']: | |
| lon = quake['geometry']['coordinates'][0] | |
| lat = quake['geometry']['coordinates'][1] | |
| depth = quake['geometry']['coordinates'][2] | |
| magnitude = quake['properties']['mag'] | |
| seconds = quake['properties']['time'] / 1000.0 | |
| qtime = datetime.datetime.fromtimestamp(seconds) | |
| print "There was a %f magnitude quake at (%f,%f) depth %f, on %d-%d-%d" % (magnitude, lat, lon, depth, qtime.year, qtime.month, qtime.day) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment