using v3 now
This commit is contained in:
@@ -90,6 +90,8 @@ SETTINGS_NAME = settings.SETTINGS_NAME
|
|||||||
UPLOAD_SERVICE_URL = settings.UPLOAD_SERVICE_URL
|
UPLOAD_SERVICE_URL = settings.UPLOAD_SERVICE_URL
|
||||||
UPLOAD_SERVICE_SECRET = settings.UPLOAD_SERVICE_SECRET
|
UPLOAD_SERVICE_SECRET = settings.UPLOAD_SERVICE_SECRET
|
||||||
NK_API_LOCATION = settings.NK_API_LOCATION
|
NK_API_LOCATION = settings.NK_API_LOCATION
|
||||||
|
TP_CLIENT_ID = settings.TP_CLIENT_ID
|
||||||
|
TP_CLIENT_SECRET = settings.TP_CLIENT_SECRET
|
||||||
|
|
||||||
from requests_oauthlib import OAuth1, OAuth1Session
|
from requests_oauthlib import OAuth1, OAuth1Session
|
||||||
|
|
||||||
@@ -299,6 +301,23 @@ def summaryfromsplitdata(splitdata, data, filename, sep='|', workouttype='rower'
|
|||||||
|
|
||||||
return sums, sa, results
|
return sums, sa, results
|
||||||
|
|
||||||
|
@app.task
|
||||||
|
def check_tp_workout_id(workout, location, attempts=5, debug=False, **kwargs):
|
||||||
|
authorizationstring = str('Bearer ' + workout.user.tptoken)
|
||||||
|
headers = {'Authorization': authorizationstring,
|
||||||
|
'user-agent': 'sanderroosendaal',
|
||||||
|
'Content-Type': 'application/json'}
|
||||||
|
response = requests.get(location, headers=headers, params={})
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
status = response.json()['Status']
|
||||||
|
if status == 'Success':
|
||||||
|
tpid = response.json()['WorkoutIds'][0]
|
||||||
|
workout.uploadedtotp = tpid
|
||||||
|
workout.save()
|
||||||
|
|
||||||
|
return 1
|
||||||
|
|
||||||
@app.task
|
@app.task
|
||||||
def instroke_static(w, metric, debug=False, **kwargs):
|
def instroke_static(w, metric, debug=False, **kwargs):
|
||||||
f1 = w.csvfilename[6:-4]
|
f1 = w.csvfilename[6:-4]
|
||||||
|
|||||||
@@ -5,6 +5,14 @@ from django_rq import job
|
|||||||
# All the functionality needed to connect to Runkeeper
|
# All the functionality needed to connect to Runkeeper
|
||||||
from rowers.imports import *
|
from rowers.imports import *
|
||||||
from rowers.utils import dologging
|
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
|
# Python
|
||||||
import gzip
|
import gzip
|
||||||
@@ -150,17 +158,24 @@ def uploadactivity(access_token, filename, description='',
|
|||||||
"Data": base64.b64encode(data_gz.getvalue()).decode("ascii")
|
"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),
|
data=json.dumps(data),
|
||||||
headers=headers, verify=False)
|
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.status_code)
|
||||||
dologging('tp_export.log',resp.reason)
|
dologging('tp_export.log',resp.reason)
|
||||||
dologging('tp_export.log',json.dumps(data))
|
dologging('tp_export.log',json.dumps(data))
|
||||||
return 0, resp.reason, resp.status_code, headers
|
return 0, resp.reason, resp.status_code, headers
|
||||||
else:
|
else:
|
||||||
return resp.json()[0]["Id"], "ok", 200, ""
|
return 1, "ok", 200, resp.headers
|
||||||
|
|
||||||
return 0, 0, 0, 0 # pragma: no cover
|
return 0, 0, 0, 0 # pragma: no cover
|
||||||
|
|
||||||
@@ -197,6 +212,12 @@ def workout_tp_upload(user, w): # pragma: no cover
|
|||||||
tpid = res
|
tpid = res
|
||||||
w.save()
|
w.save()
|
||||||
os.remove(tcxfile)
|
os.remove(tcxfile)
|
||||||
|
|
||||||
|
job = myqueue(queuelow,
|
||||||
|
check_tp_workout_id,
|
||||||
|
w,
|
||||||
|
headers['Location'])
|
||||||
|
|
||||||
return 'Successfully synchronized to TrainingPeaks', tpid
|
return 'Successfully synchronized to TrainingPeaks', tpid
|
||||||
|
|
||||||
else: # no tcxfile
|
else: # no tcxfile
|
||||||
|
|||||||
@@ -52,6 +52,11 @@ def workout_tp_upload_view(request, id=0):
|
|||||||
w.uploadedtotp = res
|
w.uploadedtotp = res
|
||||||
w.save()
|
w.save()
|
||||||
os.remove(tcxfile)
|
os.remove(tcxfile)
|
||||||
|
job = myqueue(queuelow,
|
||||||
|
check_tp_workout_id,
|
||||||
|
w,
|
||||||
|
headers['Location'])
|
||||||
|
|
||||||
messages.info(request, 'Uploaded to TrainingPeaks')
|
messages.info(request, 'Uploaded to TrainingPeaks')
|
||||||
|
|
||||||
else: # pragma: no cover # no tcxfile
|
else: # pragma: no cover # no tcxfile
|
||||||
|
|||||||
@@ -263,6 +263,7 @@ from rowers.tasks import (
|
|||||||
handle_c2_async_workout,
|
handle_c2_async_workout,
|
||||||
handle_send_email_instantplan_notification,
|
handle_send_email_instantplan_notification,
|
||||||
handle_nk_async_workout,
|
handle_nk_async_workout,
|
||||||
|
check_tp_workout_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
from scipy.signal import savgol_filter
|
from scipy.signal import savgol_filter
|
||||||
|
|||||||
Reference in New Issue
Block a user