Skip to content

Instantly share code, notes, and snippets.

@davepape
Last active March 13, 2017 12:56
Show Gist options
  • Select an option

  • Save davepape/13b6d97250d89bd216c4 to your computer and use it in GitHub Desktop.

Select an option

Save davepape/13b6d97250d89bd216c4 to your computer and use it in GitHub Desktop.
parse USGS's GeoJSON data of earthquakes
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