Private
Public Access
1
0

logging for tp export

This commit is contained in:
Sander Roosendaal
2022-05-07 17:34:29 +02:00
parent 9597cff5f5
commit 0c8ef754d1
2 changed files with 32 additions and 18 deletions

View File

@@ -37,21 +37,21 @@ class RowerInline(admin.StackedInline):
'rest', 'ut2', 'ut1', 'at', 'tr', 'an', 'hrftp',)}),
('Import/Export Keys',
{'fields': ('c2token', 'tokenexpirydate',
'c2refreshtoken', 'c2_auto_export', 'c2_auto_import',
'c2refreshtoken',
'sporttrackstoken', 'sporttrackstokenexpirydate',
'sporttracksrefreshtoken',
'sporttracks_auto_export',
'tptoken', 'tptokenexpirydate', 'tprefreshtoken',
'trainingpeaks_auto_export',
'polartoken', 'polartokenexpirydate',
'polarrefreshtoken', 'polaruserid',
'polar_auto_import',
'stravatoken', 'stravatokenexpirydate', 'stravarefreshtoken',
'stravaexportas', 'strava_auto_export',
'strava_auto_import',
'stravaexportas',
'garmintoken', 'garminrefreshtoken',
'nktoken','nkrefreshtoken','nktokenexpirydate',
'rojabo_token','rojabo_refreshtoken','rojabo_tokenexpirydate')}),
('Import/Export Settings',
{'fields': ('c2_auto_export', 'c2_auto_import',
'rp3_auto_import','nk_auto_import','trainingpeaks_auto_export',
'polar_auto_import','strava_auto_export','strava_auto_import')}),
('Team',
{'fields': ('friends', 'privacy', 'team')}),
)

View File

@@ -231,34 +231,48 @@ def do_sync(w, options, quick=False):
f.write(timestamp)
f.write(str(e))
do_tp_export = w.user.trainingpeaks_auto_export
do_st_export = w.user.sporttracks_auto_export
try: # pragma: no cover
upload_to_tp = options['upload_to_SportTracks'] or do_tp_export
do_tp_export = upload_to_tp
upload_to_st = options['upload_to_SportTracks'] or do_st_export
do_st_export = upload_to_st
except KeyError:
upload_to_tp = False
upload_to_st = False
if do_tp_export: # pragma: no cover
if do_st_export: # pragma: no cover
try:
message, id = sporttracksstuff.workout_sporttracks_upload(
w.user.user, w, asynchron=True,
)
with open('st_export.log', 'a') as logfile: # pragma: no cover
logfile.write(str(timezone.now())+': ')
logfile.write('Workout uploaded '+str(w.id)+'\n')
dologging('st_export.log',
'exported workout {wid} for user {uid}'.format(
wid = w.id,
uid = w.user.user.id,
)
)
except NoTokenError:
with open('st_export.log', 'a') as logfile:
logfile.write(str(timezone.now())+': ')
logfile.write(str(w.user)+' NoTokenError\n')
dologging('st_export.log','No Token Error')
return 0
if ('upload_to_TrainingPeaks' in options and options['upload_to_TrainingPeaks']) or (w.user.trainingpeaks_auto_export): # pragma: no cover
do_tp_export = w.user.trainingpeaks_auto_export
try:
upload_to_tp = options['upload_to_TrainingPeaks'] or do_tp_export
do_tp_export = upload_to_tp
except KeyError:
upload_to_st = False
if do_tp_export:
try:
_, id = tpstuff.workout_tp_upload(
w.user.user, w
)
dologging('tp_export.log',
'exported workout {wid} for user {uid}'.format(
wid = w.id,
uid = w.user.user.id,
)
)
except NoTokenError:
dologging('tp_export.log','No Token Error')
return 0
return 1