Skip to content

Instantly share code, notes, and snippets.

@danhammer
Created May 22, 2018 20:27
Show Gist options
  • Save danhammer/7380db259ba93faaad18b52ece461993 to your computer and use it in GitHub Desktop.
Save danhammer/7380db259ba93faaad18b52ece461993 to your computer and use it in GitHub Desktop.
An example to pull the most recent Earthrise stories
import firebase
import requests
fb = firebase.FirebaseApplication('https://overview-seeds.firebaseio.com', None)
def grab_stories(n):
# Grab the most recent `n` stories from the Where to Look (WTL) firebase
# dataset. (Some of the stories are dated far into the future, hence the
# `endAt` parameter.)
today = date.today().isoformat()
params={
'orderBy': '"publication_date"',
'limitToLast': n,
'endAt': '"%s"' % today
}
res = fb.get("/", "WTL", params=params)
stories = res.values()
sorted_stories = sorted(
stories,
key=lambda x: x['publication_date'],
reverse=True
)
return sorted_stories
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment