fixing c2 import
This commit is contained in:
@@ -183,10 +183,26 @@ def get_c2_workouts(rower,do_async=True):
|
||||
t.uploadedtoc2 for t in TombStone.objects.filter(user=rower)
|
||||
]
|
||||
|
||||
knownc2ids = uniqify(knownc2ids+tombstones)
|
||||
# get "blocked" c2ids
|
||||
parkedids = []
|
||||
try:
|
||||
with open('c2blocked.json','r') as c2blocked:
|
||||
jsondata = json.load(c2blocked)
|
||||
parkedids = jsondata['ids']
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
|
||||
knownc2ids = uniqify(knownc2ids+tombstones+parkedids)
|
||||
|
||||
newids = [c2id for c2id in c2ids if not c2id in knownc2ids]
|
||||
|
||||
newparkedids = uniqify(newids+parkedids)
|
||||
|
||||
with open('c2blocked.json','wt') as c2blocked:
|
||||
data = {'ids':newparkedids}
|
||||
json.dump(data,c2blocked)
|
||||
|
||||
for c2id in newids:
|
||||
if do_async:
|
||||
res = myqueue(queuehigh,
|
||||
@@ -372,6 +388,20 @@ def create_async_workout(alldata,user,c2id):
|
||||
except KeyError:
|
||||
workoutid = 1
|
||||
|
||||
newc2id = Workout.objects.get(id=workoutid).uploadedtoc2
|
||||
|
||||
parkedids = []
|
||||
with open('c2blocked.json','r') as c2blocked:
|
||||
jsondata = json.load(c2blocked)
|
||||
parkedids = jsondata['ids']
|
||||
|
||||
newparkedids = [id for id in parkedids if id != newc2id]
|
||||
with open('c2blocked.json','wt') as c2blocked:
|
||||
data = {'ids':newparkedids}
|
||||
c2blocked.seek(0)
|
||||
json.dump(data,c2blocked)
|
||||
|
||||
|
||||
return workoutid
|
||||
|
||||
|
||||
|
||||
@@ -203,9 +203,9 @@ class Command(BaseCommand):
|
||||
|
||||
# Concept2
|
||||
rowers = Rower.objects.filter(c2_auto_import=True)
|
||||
#for r in rowers:
|
||||
# if user_is_not_basic(r.user):
|
||||
# c2stuff.get_c2_workouts(r)
|
||||
for r in rowers:
|
||||
if user_is_not_basic(r.user):
|
||||
c2stuff.get_c2_workouts(r)
|
||||
|
||||
|
||||
messages = Message.objects.filter(mailbox_id = workoutmailbox.id)
|
||||
|
||||
@@ -2871,6 +2871,32 @@ def handle_c2_async_workout(alldata,userid,c2token,c2id,debug=False,**kwargs):
|
||||
|
||||
workoutid = response.json()['id']
|
||||
|
||||
if debug:
|
||||
engine = create_engine(database_url_debug, echo=False)
|
||||
else:
|
||||
engine = create_engine(database_url, echo=False)
|
||||
|
||||
query = 'SELECT uploadedtoc2 from rowers_workout WHERE id ={workoutid}'.format(workoutid=workoutid)
|
||||
|
||||
newc2id = 0
|
||||
with engine.connect() as conn, conn.begin():
|
||||
result = conn.execute(query)
|
||||
data = result.fetchall()
|
||||
newc2id = data[0][0]
|
||||
|
||||
conn.close()
|
||||
|
||||
parkedids = []
|
||||
with open('c2blocked.json','r') as c2blocked:
|
||||
jsondata = json.load(c2blocked)
|
||||
parkedids = jsondata['ids']
|
||||
|
||||
newparkedids = [id for id in parkedids if id != newc2id]
|
||||
with open('c2blocked.json','wt') as c2blocked:
|
||||
data = {'ids':newparkedids}
|
||||
c2blocked.seek(0)
|
||||
json.dump(data,c2blocked)
|
||||
|
||||
return workoutid
|
||||
|
||||
|
||||
|
||||
@@ -524,8 +524,6 @@ def make_private(w,options):
|
||||
return 1
|
||||
|
||||
def do_sync(w,options, quick=False):
|
||||
if w.duplicate:
|
||||
return 0
|
||||
|
||||
try:
|
||||
upload_to_strava = options['upload_to_Strava']
|
||||
@@ -553,8 +551,6 @@ def do_sync(w,options, quick=False):
|
||||
except KeyError:
|
||||
upload_to_c2 = False
|
||||
|
||||
|
||||
|
||||
try:
|
||||
if options['c2id'] != 0 and options['c2id'] != '':
|
||||
w.uploadedtoc2 = options['c2id']
|
||||
@@ -563,6 +559,9 @@ def do_sync(w,options, quick=False):
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
if w.duplicate:
|
||||
return 0
|
||||
|
||||
if ('upload_to_C2' in options and upload_to_c2) or (w.user.c2_auto_export):
|
||||
try:
|
||||
message,id = c2stuff.workout_c2_upload(w.user.user,w,asynchron=True)
|
||||
|
||||
@@ -4774,6 +4774,7 @@ def workout_upload_api(request):
|
||||
except KeyError:
|
||||
c2id = ''
|
||||
|
||||
|
||||
try:
|
||||
garminid = post_data['garminid']
|
||||
except KeyError:
|
||||
@@ -4865,14 +4866,17 @@ def workout_upload_api(request):
|
||||
|
||||
w = Workout.objects.get(id=id)
|
||||
|
||||
|
||||
if make_plot:
|
||||
res, jobid = uploads.make_plot(r,w,f1,f2,plottype,t)
|
||||
elif r.staticchartonupload != 'None':
|
||||
plottype = r.staticchartonupload
|
||||
res, jobid = uploads.make_plot(r,w,f1,f2,plottype,t)
|
||||
|
||||
|
||||
uploads.do_sync(w,post_data,quick=True)
|
||||
|
||||
|
||||
else: # form invalid
|
||||
if fstr:
|
||||
os.remove(fstr)
|
||||
|
||||
Reference in New Issue
Block a user