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',)}), 'rest', 'ut2', 'ut1', 'at', 'tr', 'an', 'hrftp',)}),
('Import/Export Keys', ('Import/Export Keys',
{'fields': ('c2token', 'tokenexpirydate', {'fields': ('c2token', 'tokenexpirydate',
'c2refreshtoken', 'c2_auto_export', 'c2_auto_import', 'c2refreshtoken',
'sporttrackstoken', 'sporttrackstokenexpirydate', 'sporttrackstoken', 'sporttrackstokenexpirydate',
'sporttracksrefreshtoken', 'sporttracksrefreshtoken',
'sporttracks_auto_export',
'tptoken', 'tptokenexpirydate', 'tprefreshtoken', 'tptoken', 'tptokenexpirydate', 'tprefreshtoken',
'trainingpeaks_auto_export',
'polartoken', 'polartokenexpirydate', 'polartoken', 'polartokenexpirydate',
'polarrefreshtoken', 'polaruserid', 'polarrefreshtoken', 'polaruserid',
'polar_auto_import',
'stravatoken', 'stravatokenexpirydate', 'stravarefreshtoken', 'stravatoken', 'stravatokenexpirydate', 'stravarefreshtoken',
'stravaexportas', 'strava_auto_export', 'stravaexportas',
'strava_auto_import',
'garmintoken', 'garminrefreshtoken', 'garmintoken', 'garminrefreshtoken',
'nktoken','nkrefreshtoken','nktokenexpirydate', 'nktoken','nkrefreshtoken','nktokenexpirydate',
'rojabo_token','rojabo_refreshtoken','rojabo_tokenexpirydate')}), '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', ('Team',
{'fields': ('friends', 'privacy', 'team')}), {'fields': ('friends', 'privacy', 'team')}),
) )

View File

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