concept2 auto import
This commit is contained in:
@@ -34,7 +34,7 @@ import sys
|
||||
import urllib
|
||||
from requests import Request, Session
|
||||
|
||||
from utils import myqueue
|
||||
from utils import myqueue,uniqify,isprorower
|
||||
|
||||
from rowers.types import otwtypes
|
||||
|
||||
@@ -114,7 +114,37 @@ def add_stroke_data(user,c2id,workoutid,startdatetime,csvfilename):
|
||||
csvfilename)
|
||||
|
||||
return 1
|
||||
|
||||
def get_c2_workouts(rower):
|
||||
|
||||
if not isprorower(rower):
|
||||
return 0
|
||||
|
||||
try:
|
||||
thetoken = c2_open(rower.user)
|
||||
except C2NoTokenError:
|
||||
return 0
|
||||
|
||||
res = get_c2_workout_list(rower.user,page=1)
|
||||
|
||||
if (res.status_code != 200):
|
||||
return 0
|
||||
else:
|
||||
c2ids = [item['id'] for item in res.json()['data']]
|
||||
alldata = {}
|
||||
for item in res.json()['data']:
|
||||
alldata[item['id']] = item
|
||||
|
||||
knownc2ids = uniqify([
|
||||
w.uploadedtoc2 for w in Workout.objects.filter(user=rower)
|
||||
])
|
||||
newids = [c2id for c2id in c2ids if not c2id in knownc2ids]
|
||||
|
||||
for c2id in newids:
|
||||
workoutid = create_async_workout(alldata,
|
||||
rower.user,c2id)
|
||||
|
||||
return 1
|
||||
|
||||
# get workout metrics, then relay stroke data to an asynchronous task
|
||||
def create_async_workout(alldata,user,c2id):
|
||||
@@ -155,7 +185,7 @@ def create_async_workout(alldata,user,c2id):
|
||||
w = Workout(
|
||||
user=r,
|
||||
workouttype = workouttype,
|
||||
name = 'Imported workout',
|
||||
name = 'C2 Import Workout from {startdatetime}'.format(startdatetime=startdatetime),
|
||||
date = workoutdate,
|
||||
starttime = starttime,
|
||||
startdatetime = startdatetime,
|
||||
|
||||
Reference in New Issue
Block a user