Private
Public Access
1
0

adding async option to NK import

This commit is contained in:
Sander Roosendaal
2021-04-19 08:41:48 +02:00
parent 2deb4fcbe3
commit 0c13f798de
9 changed files with 42 additions and 12 deletions

View File

@@ -247,7 +247,7 @@ def get_nk_workout_list(user,fake=False,after=0,before=0):
#
def get_workout(user,nkid):
def get_workout(user,nkid,do_async=False):
r = Rower.objects.get(user=user)
if (r.nktoken == '') or (r.nktoken is None):
s = "Token doesn't exist. Need to authorize"
@@ -260,6 +260,27 @@ def get_workout(user,nkid):
'sessionIds': nkid,
}
if do_async:
res = get_nk_workout_list(r.user)
if res.status_code != 200:
return 0
alldata = {}
for item in res.json():
alldata[item['id']] = item
res = myqueue(
queuehigh,
handle_nk_async_workout,
alldata,
r.user.id,
r.nktoken,
nkid,
0,
r.defaulttimezone,
)
return {},pd.DataFrame()
authorizationstring = str('Bearer ' + r.nktoken)
headers = {'Authorization': authorizationstring,
@@ -292,7 +313,6 @@ def get_workout(user,nkid):
before = before+timedelta(days=1)
before = str(int(before.timestamp())*1000)
after = str(int(after.timestamp())*1000)
print(after)
url = NK_API_LOCATION+"api/v1/sessions/"