mirror of
https://github.com/sstent/containers.git
synced 2025-12-06 08:01:51 +00:00
Update run_collect.py
tidy
This commit is contained in:
@@ -37,38 +37,11 @@ USER_DETAILS_FILE = 'user_details.json' # user details file
|
||||
|
||||
RESULT_FILE = 'fitbit_data.json' # The place where we will place the results
|
||||
|
||||
|
||||
# def refresh_callback(token):
|
||||
# """
|
||||
# This method is only called when the authenticate token is out of date
|
||||
# and a new token has been issued which needs to be stored somewhere for
|
||||
# the next run
|
||||
# param (token): A dictionary with the new details
|
||||
# """
|
||||
# print('CALLBACK: The token has been updated since last run')
|
||||
# with open(USER_DETAILS_FILE, 'w') as f:
|
||||
# json.dump(token, f)
|
||||
# print('Successfully written update refresh token')
|
||||
|
||||
def refresh_callback(token):
|
||||
c.kv.put('access_token', token["access_token"])
|
||||
c.kv.put('refresh_token', token["refresh_token"])
|
||||
c.kv.put('expires_at', str(token["expires_at"]))
|
||||
|
||||
# def _get_user_details():
|
||||
# """
|
||||
# The specific user that you want to retrieve data for.
|
||||
# """
|
||||
# with open(USER_DETAILS_FILE) as f:
|
||||
# fitbit_user = json.load(f)
|
||||
# access_token = fitbit_user['access_token']
|
||||
# refresh_token = fitbit_user['refresh_token']
|
||||
# expires_at = fitbit_user['expires_at']
|
||||
|
||||
# print(type(expires_at))
|
||||
# return access_token, refresh_token, expires_at
|
||||
|
||||
|
||||
|
||||
def _get_user_details():
|
||||
access_token = c.kv.get('access_token')[1]["Value"].decode("utf-8")
|
||||
@@ -112,8 +85,6 @@ def _get_api_call():
|
||||
# # Sleep between two dates
|
||||
# sleep_dates = '/1.2/user/-/sleep/date/2020-04-13/2020-04-17.json'
|
||||
weight = '/1.2/user/-/body/log/weight/date/' + str(date_start) + '/' + str(date_end) + '.json'
|
||||
# print("API:", weight)
|
||||
|
||||
return weight
|
||||
|
||||
|
||||
@@ -175,25 +146,6 @@ def UpdateSheet(values):
|
||||
|
||||
service = build('sheets', 'v4', credentials=creds)
|
||||
|
||||
# Call the Sheets API
|
||||
# sheet = service.spreadsheets()
|
||||
# result = sheet.values().get(spreadsheetId=SAMPLE_SPREADSHEET_ID,
|
||||
# range=SAMPLE_RANGE_NAME).execute()
|
||||
# values = result.get('values', [])
|
||||
|
||||
# if not values:
|
||||
# print('No data found.')
|
||||
# else:
|
||||
# print('Name, Major:')
|
||||
# for row in values:
|
||||
# # Print columns A and E, which correspond to indices 0 and 4.
|
||||
# print('%s, %s' % (row[0], row[4]))
|
||||
|
||||
# values = [
|
||||
# [
|
||||
# "TEST", "TEST"
|
||||
# ],
|
||||
# ]
|
||||
body = {
|
||||
'values': values
|
||||
}
|
||||
@@ -217,8 +169,6 @@ def run():
|
||||
|
||||
|
||||
|
||||
#print(f'Running Fitbit request with details: {client_id} {client_secret}'
|
||||
# f' {access_token} {refresh_token} {expires_at}')
|
||||
auth2_client = Fitbit(client_id, client_secret, oauth2=True,
|
||||
access_token=access_token,
|
||||
refresh_token=refresh_token, expires_at=expires_at,
|
||||
@@ -226,11 +176,8 @@ def run():
|
||||
|
||||
fitbit_url = FITBIT_API + _get_api_call()
|
||||
json_response = auth2_client.make_request(fitbit_url)
|
||||
# _write_results(json_response)
|
||||
# pprint(json_response["weight"])
|
||||
values = []
|
||||
sheet_values = ReadSheet()
|
||||
# pprint(sheet_values)
|
||||
|
||||
for row in json_response["weight"]:
|
||||
row_exists = 0
|
||||
@@ -244,10 +191,8 @@ def run():
|
||||
else:
|
||||
row_list = [row["date"],row["weight"],"0",row["bmi"]]
|
||||
values.append(row_list)
|
||||
# pprint(date_start)
|
||||
pprint(values)
|
||||
UpdateSheet(values)
|
||||
# sheet_values = ReadSheet()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -258,15 +203,3 @@ if __name__ == '__main__':
|
||||
print("Grabbin': ", date_start, date_end)
|
||||
run()
|
||||
|
||||
###Bulk import
|
||||
# date_start = date(2015, 8, 1)
|
||||
# end_date = date(2021, 11, 1)
|
||||
|
||||
# while date_start != end_date:
|
||||
# # date_end = date.today() + timedelta(30)
|
||||
# date_end = date_start + timedelta(30)
|
||||
# print(date_start, date_end)
|
||||
# # date_start = date.today() - timedelta(31)
|
||||
# # run()
|
||||
# # time.sleep(10)
|
||||
# date_start = date_start - timedelta(1)
|
||||
|
||||
Reference in New Issue
Block a user