Private
Public Access
1
0

using v3 now

This commit is contained in:
Sander Roosendaal
2022-08-17 02:44:48 +02:00
parent a7773a6f4a
commit b88aa0a246
4 changed files with 49 additions and 3 deletions

View File

@@ -5,6 +5,14 @@ from django_rq import job
# All the functionality needed to connect to Runkeeper
from rowers.imports import *
from rowers.utils import dologging
from rowers.tasks import check_tp_workout_id
import django_rq
queue = django_rq.get_queue('default')
queuelow = django_rq.get_queue('low')
queuehigh = django_rq.get_queue('low')
from rowers.utils import myqueue
# Python
import gzip
@@ -150,17 +158,24 @@ def uploadactivity(access_token, filename, description='',
"Data": base64.b64encode(data_gz.getvalue()).decode("ascii")
}
resp = requests.post(tpapilocation+"/v2/file/synchronous",
#resp = requests.post(tpapilocation+"/v2/file/synchronous",
# data=json.dumps(data),
# headers=headers, verify=False)
resp = requests.post(tpapilocation+"/v3/file",
data=json.dumps(data),
headers=headers, verify=False)
if resp.status_code != 200: # pragma: no cover
print(resp.headers['Location'])
if resp.status_code not in (200, 202): # pragma: no cover
dologging('tp_export.log',resp.status_code)
dologging('tp_export.log',resp.reason)
dologging('tp_export.log',json.dumps(data))
return 0, resp.reason, resp.status_code, headers
else:
return resp.json()[0]["Id"], "ok", 200, ""
return 1, "ok", 200, resp.headers
return 0, 0, 0, 0 # pragma: no cover
@@ -197,6 +212,12 @@ def workout_tp_upload(user, w): # pragma: no cover
tpid = res
w.save()
os.remove(tcxfile)
job = myqueue(queuelow,
check_tp_workout_id,
w,
headers['Location'])
return 'Successfully synchronized to TrainingPeaks', tpid
else: # no tcxfile