| | |
| | |
| | |
| | import json |
| | import gspread |
| | import os |
| | import pandas as pd |
| | from oauth2client.service_account import ServiceAccountCredentials |
| |
|
| | def connect_to_sheet(): |
| | creds_dict = json.loads(os.environ["GOOGLE_CREDS_JSON"]) |
| | scope = [ |
| | "https://spreadsheets.google.com/feeds", |
| | "https://www.googleapis.com/auth/spreadsheets", |
| | "https://www.googleapis.com/auth/drive" |
| | ] |
| | creds = ServiceAccountCredentials.from_json_keyfile_dict(creds_dict, scope) |
| | client = gspread.authorize(creds) |
| | sheet = client.open("Hackathon Leaderboard").sheet1 |
| | return sheet |
| |
|
| | def append_score(timestamp, score, filename): |
| | sheet = connect_to_sheet() |
| | sheet.append_row([timestamp, score, filename]) |
| |
|
| | def fetch_leaderboard(): |
| | sheet = connect_to_sheet() |
| | data = sheet.get_all_records() |
| | return pd.DataFrame(data) |