Created
May 22, 2018 20:27
-
-
Save danhammer/7380db259ba93faaad18b52ece461993 to your computer and use it in GitHub Desktop.
An example to pull the most recent Earthrise stories
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
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