Save Garmin Connect tokens

This commit is contained in:
oldnapalm
2023-09-29 11:58:08 -03:00
parent 11e52633a0
commit 7d190847e2
+11 -1
View File
@@ -2082,8 +2082,18 @@ def garmin_upload(player_id, activity):
except Exception as exc:
logger.warning("Failed to read %s. Skipping Garmin upload attempt: %s" % (garmin_credentials, repr(exc)))
return
tokens_dir = '%s/garth' % profile_dir
try:
garth.resume(tokens_dir)
garth.client.username
except:
try:
garth.login(username, password)
garth.save(tokens_dir)
except Exception as exc:
logger.warning("Garmin login failed: %s" % repr(exc))
return
try:
garth.login(username, password)
requests.post('https://connect.garmin.com/upload-service/upload/.fit', files={'file': BytesIO(activity.fit)},
headers={'NK': 'NT', 'authorization': garth.client.oauth2_token.__str__(), 'di-backend': 'connectapi.garmin.com'})
except Exception as exc: