Spaces:
Sleeping
Sleeping
Update src/data_upload.py
Browse files- src/data_upload.py +17 -10
src/data_upload.py
CHANGED
|
@@ -1,17 +1,24 @@
|
|
| 1 |
-
|
| 2 |
-
|
|
|
|
| 3 |
|
| 4 |
def connect_to_sheet():
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
client = gspread.authorize(creds)
|
| 11 |
-
|
| 12 |
-
sheet = client.open("leaderboard").sheet1
|
| 13 |
return sheet
|
| 14 |
|
| 15 |
def append_score(timestamp, score, filename):
|
| 16 |
sheet = connect_to_sheet()
|
| 17 |
-
sheet.append_row([timestamp, score, filename])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ========================
|
| 2 |
+
# Google Sheets Integration
|
| 3 |
+
# ========================
|
| 4 |
|
| 5 |
def connect_to_sheet():
|
| 6 |
+
creds_dict = json.loads(os.environ["GOOGLE_CREDS_JSON"])
|
| 7 |
+
scope = [
|
| 8 |
+
"https://spreadsheets.google.com/feeds",
|
| 9 |
+
"https://www.googleapis.com/auth/spreadsheets",
|
| 10 |
+
"https://www.googleapis.com/auth/drive"
|
| 11 |
+
]
|
| 12 |
+
creds = ServiceAccountCredentials.from_json_keyfile_dict(creds_dict, scope)
|
| 13 |
client = gspread.authorize(creds)
|
| 14 |
+
sheet = client.open("Hackathon Leaderboard").sheet1
|
|
|
|
| 15 |
return sheet
|
| 16 |
|
| 17 |
def append_score(timestamp, score, filename):
|
| 18 |
sheet = connect_to_sheet()
|
| 19 |
+
sheet.append_row([timestamp, score, filename])
|
| 20 |
+
|
| 21 |
+
def fetch_leaderboard():
|
| 22 |
+
sheet = connect_to_sheet()
|
| 23 |
+
data = sheet.get_all_records()
|
| 24 |
+
return pd.DataFrame(data)
|