Spaces:
Sleeping
Sleeping
Create google_sheet.py
Browse files- src/google_sheet.py +24 -0
src/google_sheet.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|