Skip to content

Instantly share code, notes, and snippets.

@bennettscience
Created October 7, 2017 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bennettscience/454e64aa5ce74c70277bd9b77a5609e8 to your computer and use it in GitHub Desktop.
Save bennettscience/454e64aa5ce74c70277bd9b77a5609e8 to your computer and use it in GitHub Desktop.
Download and sort a Google Sheet as JSON
#! /usr/local/bin/python
import json, requests
# Your Google Sheet as JSON feed
url = "https://spreadsheets.google.com/feeds/list/YOUR_KEY_HERE/od6/public/values?alt=json"
# Get the data and store it as a dictionary you can sort
r = requests.get(url)
logs = r.json()
list = []
# Turn the whole feed into an iterable list
for log in logs['feed']['entry']:
list.append((log['gsx$timestamp']['$t'], log['gsx$action']['$t']))
# Show the last 5 items only
for item in list[-5:]:
print ('%s %s' % (item[0], item[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment