Merge branch 'release/v15.18'
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -160,20 +160,14 @@ def get_c2_workouts(rower):
|
||||
try:
|
||||
thetoken = c2_open(rower.user)
|
||||
except NoTokenError:
|
||||
with open('c2_auto_import.log','a') as logfile:
|
||||
logfile.write('c2_open fail \n')
|
||||
return 0
|
||||
return 0
|
||||
|
||||
res = get_c2_workout_list(rower.user,page=1)
|
||||
|
||||
if (res.status_code != 200):
|
||||
with open('c2_auto_import.log') as logfile:
|
||||
logfile.write('Status code != 200\n')
|
||||
return 0
|
||||
else:
|
||||
c2ids = [item['id'] for item in res.json()['data']]
|
||||
with open('c2_auto_import.log','a') as logfile:
|
||||
logfile.write(json.dumps(c2ids)+'\n')
|
||||
alldata = {}
|
||||
for item in res.json()['data']:
|
||||
alldata[item['id']] = item
|
||||
@@ -191,13 +185,8 @@ def get_c2_workouts(rower):
|
||||
newids = [c2id for c2id in c2ids if not c2id in knownc2ids]
|
||||
|
||||
for c2id in newids:
|
||||
with open('c2_auto_import.log','a') as logfile:
|
||||
logfile.write('Creating async workout for c2id {c2id}\n'.format(c2id=c2id))
|
||||
|
||||
workoutid = create_async_workout(alldata,
|
||||
rower.user,c2id)
|
||||
with open('c2_auto_import.log','a') as logfile:
|
||||
logfile.write('Local workout id {workoutid}\n'.format(workoutid=workoutid))
|
||||
|
||||
|
||||
return 1
|
||||
@@ -808,14 +797,10 @@ def get_c2_workout_list(user,page=1):
|
||||
r = Rower.objects.get(user=user)
|
||||
if (r.c2token == '') or (r.c2token is None):
|
||||
s = "Token doesn't exist. Need to authorize"
|
||||
with open('c2_auto_import.log') as logfile:
|
||||
logfile.write('get_c2_workout_list - token does not exist\n')
|
||||
return custom_exception_handler(401,s)
|
||||
elif (timezone.now()>r.tokenexpirydate):
|
||||
s = "Token expired. Needs to refresh."
|
||||
with open('c2_auto_import.log') as logfile:
|
||||
logfile.write('get_c2_workout_list - token expires\n')
|
||||
|
||||
|
||||
return custom_exception_handler(401,s)
|
||||
else:
|
||||
# ready to fetch. Hurray
|
||||
|
||||
@@ -205,10 +205,7 @@ class Command(BaseCommand):
|
||||
rowers = Rower.objects.filter(c2_auto_import=True)
|
||||
for r in rowers:
|
||||
if user_is_not_basic(r.user):
|
||||
with open('c2_auto_import.log','a') as logfile:
|
||||
logfile.write(str(timezone.now())+" "+str(r.user)+" \n")
|
||||
logfile.write(' getting workouts \n')
|
||||
c2stuff.get_c2_workouts(r)
|
||||
c2stuff.get_c2_workouts(r)
|
||||
|
||||
|
||||
messages = Message.objects.filter(mailbox_id = workoutmailbox.id)
|
||||
|
||||
@@ -41,6 +41,7 @@ from mock import Mock, patch
|
||||
import pandas as pd
|
||||
import rowers.c2stuff as c2stuff
|
||||
import arrow
|
||||
from django.http import HttpResponseRedirect
|
||||
|
||||
import json
|
||||
import numpy as np
|
||||
@@ -145,6 +146,9 @@ def mocked_read_df_sql(id):
|
||||
|
||||
return df
|
||||
|
||||
def mocked_sendmail(*args,**kwargs):
|
||||
return HttpResponseRedirect('/rowers/email/')
|
||||
|
||||
def mocked_get_video_data(*args, **kwargs):
|
||||
with open('rowers/tests/testdata/videodata.json','r') as infile:
|
||||
data = json.load(infile)
|
||||
|
||||
@@ -260,13 +260,15 @@ class URLTests(TestCase):
|
||||
@patch('requests.get',side_effect=mocked_requests)
|
||||
@patch('requests.post',side_effect=mocked_requests)
|
||||
@patch('rowers.dataprep.get_video_data',side_effect=mocked_get_video_data)
|
||||
@patch('rowers.views.statements.sendmail',side_effect=mocked_sendmail)
|
||||
def test_url_generator(self,url,expected,
|
||||
mocked_sqlalchemy,
|
||||
mocked_read_df_sql,
|
||||
mocked_getsmallrowdata_db,
|
||||
mock_get,
|
||||
mock_post,
|
||||
mocked_get_video_data):
|
||||
mocked_get_video_data,
|
||||
mocked_sendmail):
|
||||
|
||||
if url not in tested:
|
||||
login = self.c.login(username='john',password='koeinsloot')
|
||||
|
||||
@@ -583,7 +583,13 @@ def do_sync(w,options, quick=False):
|
||||
message,id = sporttracksstuff.workout_sporttracks_upload(
|
||||
w.user.user,w,asynchron=True,
|
||||
)
|
||||
with open('st_export.log','a') as logfile:
|
||||
logfile.write(str(timezone.now())+': ')
|
||||
logfile.write('Workout uploaded '+w.id+'\n')
|
||||
except NoTokenError:
|
||||
with open('st_export.log','a') as logfile:
|
||||
logfile.write(str(timezone.now())+': ')
|
||||
logfile.write(str(w.user)+' NoTokenError\n')
|
||||
message = "Please connect to SportTracks first"
|
||||
id = 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user