File size: 936 Bytes
212ad81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f844ce5
212ad81
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# ========================
# Google Sheets Integration
# ========================
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_by_key("109h0Yj8RmKEbWCj5TdJNXXbWhmaVH8o3r3q4_Pa50g8").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)