Last active
December 26, 2015 16:19
-
-
Save cclauss/7179270 to your computer and use it in GitHub Desktop.
earthQuakes - A starter experiment with Socrata Open Data
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
#!/usr/bin/env python | |
import json, requests, pprint | |
minMagnitude = 5.5 | |
rootURL = 'https://soda.demo.socrata.com/resource/' | |
theURL = rootURL + 'earthquakes.json?$where=magnitude>' + str(minMagnitude) | |
fmt = '{datetime} {earthquake_id} {version} {magnitude} {depth:>6} {location[latitude]:>8} {location[longitude]:>8} {region}' | |
def soda2FieldDictFromHeaders(inRequestsHeader): | |
fieldNames = eval(inRequestsHeader['x-soda2-fields']) | |
fieldTypes = eval(inRequestsHeader['x-soda2-types']) | |
fieldDict = {} | |
for i in xrange(len(fieldNames)): | |
fieldDict[fieldNames[i]] = fieldTypes[i] | |
return fieldDict | |
theRequest = requests.get(theURL) | |
fieldDict = soda2FieldDictFromHeaders(theRequest.headers) | |
pprint.pprint(fieldDict) | |
print('') | |
for quakeDict in json.loads(theRequest.text): | |
# pprint.pprint(quakeDict) | |
print(fmt.format(**quakeDict)) | |
print('=' * 75) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment