Created
September 17, 2020 21:04
-
-
Save daydreamersjp/c9b95c4b72e13f6d04353948abb31359 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import datetime | |
| import gspread | |
| import urllib.request | |
| import pandas as pd | |
| event = "Arrived at office." # Whatever event you want to record in the sheet. | |
| FRT = datetime.timezone(datetime.timedelta(hours=+2)) | |
| def record_to_sheets(request): | |
| # Copy service account json file to local. | |
| if not os.path.isfile('/tmp/service_account.json'): | |
| urllib.request.urlretrieve(<URL to JSON of service accout key>,"/tmp/service_account.json") | |
| # gspread client. | |
| client = gspread.service_account(filename='/tmp/service_account.json') | |
| # Access target sheet. | |
| sheet = client.open("Record iPhone Click").sheet1 | |
| # event record data frame. | |
| eve_df = pd.DataFrame({'event':[event], 'time':[str(datetime.datetime.now(FRT))]}) | |
| # Record event to target sheet. | |
| sheet.insert_rows(eve_df.values.tolist(),2) | |
| return event + " noted!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment