Created
November 2, 2019 01:02
-
-
Save hfuller/b50353b832b5031499f4a4ff1fa418eb to your computer and use it in GitHub Desktop.
Poll for Extra Life donation record-holders and write the data to files (to use in OBS)
This file contains 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 urllib.request | |
import json | |
import time | |
team_id = 48709 | |
url = "https://www.extra-life.org/api/teams/" + str(team_id) + "/donations" | |
def get_name(donation_data): | |
try: | |
return donation_data['displayName'] | |
except: | |
return "Anonymous" | |
while True: | |
stuff = json.load(urllib.request.urlopen(url)) | |
#most recent | |
stuff.sort(key=lambda x: x['createdDateUTC'], reverse=True) | |
print("MOST RECENT:", stuff[1]) | |
with open("extralife-donation-recent.txt", 'w') as f: | |
f.write(get_name(stuff[0])) | |
#largest amount | |
stuff.sort(key=lambda x: x['amount'], reverse=True) | |
#but what if multiple people donated the same amount? | |
amount = stuff[0]['amount'] | |
stuff = [x for x in stuff if x['amount'] == amount] | |
print("LARGEST AMT:", amount, stuff) | |
with open("extralife-donation-largest.txt", 'w') as f: | |
for x in stuff: | |
f.write(get_name(x) + '\n') | |
time.sleep(60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment