Source

yrsdata / data5.py

Full commit
# Example of using Requests to download data from a URL,
# followed by Tablib to process the data

import requests
import tablib

url = 'http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M5.txt'

response = requests.get(url)

data = tablib.Dataset()
data.csv = response.text   # yes, it really is that simple!
                           # for JSON data, assign to data.json

print 'Dataset has', len(data), 'rows'
print 'Headers:', data.headers
print 'Magnitudes:', data['Magnitude']

print 'Exporting as JSON to data.json...'
with open('data.json', 'w') as outfile:
    outfile.write(data.json)

print 'Exporting as OpenDocument Spreadsheet to data.ods...'
with open('data.ods', 'wb') as outfile:
    outfile.write(data.ods)

# Note: similar approach will export data to Excel spreadsheets
# (both .xls and .xlsx formats are supported)