SD_Hackathon / src /google_sheet.py
com3dian's picture
Create google_sheet.py
a80bcaa verified
raw
history blame
782 Bytes
# ========================
# Google Sheets Integration
# ========================
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)