Seems to work (golang routine to test)
This commit is contained in:
@@ -22,7 +22,7 @@ from rowsandall_app.settings import (
|
||||
|
||||
from pytz import timezone as tz, utc
|
||||
|
||||
from rowers.tasks import handle_c2_import_stroke_data, handle_c2_sync
|
||||
from rowers.tasks import handle_get_garmin_file
|
||||
import django_rq
|
||||
queue = django_rq.get_queue('default')
|
||||
queuelow = django_rq.get_queue('low')
|
||||
@@ -112,14 +112,16 @@ def garmin_open(user):
|
||||
return token
|
||||
|
||||
def get_garmin_file(r,callbackURL,starttime,fileType):
|
||||
job = queuehigh.enqueue(
|
||||
get_garmin_file,
|
||||
job = myqueue(
|
||||
queue,
|
||||
handle_get_garmin_file,
|
||||
oauth_data['client_id'],
|
||||
oauth_data['client_secret'],
|
||||
garmintoken,
|
||||
garminrefreshtoken,
|
||||
r.garmintoken,
|
||||
r.garminrefreshtoken,
|
||||
r.user.id,
|
||||
callbackURL,filetype
|
||||
callbackURL,
|
||||
fileType,
|
||||
)
|
||||
|
||||
return job.id
|
||||
|
||||
@@ -12,6 +12,7 @@ import shutil
|
||||
import numpy as np
|
||||
import re
|
||||
import sys
|
||||
import json
|
||||
|
||||
from scipy import optimize
|
||||
from scipy.signal import savgol_filter
|
||||
@@ -50,6 +51,7 @@ from rowsandall_app.settings import SETTINGS_NAME
|
||||
from rowsandall_app.settings import workoutemailbox
|
||||
from rowsandall_app.settings import UPLOAD_SERVICE_SECRET, UPLOAD_SERVICE_URL
|
||||
|
||||
from requests_oauthlib import OAuth1, OAuth1Session
|
||||
|
||||
import pandas as pd
|
||||
|
||||
@@ -680,8 +682,19 @@ def handle_getagegrouprecords(self,
|
||||
|
||||
return 1
|
||||
|
||||
@app.task(bind=True)
|
||||
def get_garmin_file(client_id,client_secret,garmintoken,garminrefreshtoken,userid,url,filetype):
|
||||
@app.task
|
||||
def handle_get_garmin_file(client_id,
|
||||
client_secret,
|
||||
garmintoken,
|
||||
garminrefreshtoken,
|
||||
userid,
|
||||
url,
|
||||
filetype,
|
||||
*args,
|
||||
**kwargs):
|
||||
|
||||
|
||||
|
||||
garmin = OAuth1Session(client_id,
|
||||
client_secret=client_secret,
|
||||
resource_owner_key=garmintoken,
|
||||
@@ -694,6 +707,7 @@ def get_garmin_file(client_id,client_secret,garmintoken,garminrefreshtoken,useri
|
||||
)+filetype
|
||||
|
||||
response = garmin.get(url, stream=True)
|
||||
print(response.status_code,filename)
|
||||
if response.status_code == 200:
|
||||
with open(filename, 'wb') as out_file:
|
||||
shutil.copyfileobj(response.raw, out_file)
|
||||
@@ -704,10 +718,14 @@ def get_garmin_file(client_id,client_secret,garmintoken,garminrefreshtoken,useri
|
||||
'secret':UPLOAD_SERVICE_SECRET,
|
||||
'user':userid,
|
||||
'file': filename,
|
||||
'title': 'Import from Garmin File'
|
||||
'title': filename[6:],
|
||||
'workouttype':'water',
|
||||
'boattype':'1x',
|
||||
}
|
||||
|
||||
response = requests.post(UPLOAD_SERVICE_URL,data=uploadoptions)
|
||||
session = requests.session()
|
||||
newHeaders = {'Content-type': 'application/json', 'Accept': 'text/plain'}
|
||||
session.headers.update(newHeaders)
|
||||
response = session.post(UPLOAD_SERVICE_URL,json=uploadoptions)
|
||||
|
||||
return 1
|
||||
|
||||
|
||||
@@ -416,6 +416,7 @@ urlpatterns = [
|
||||
views.WorkoutDelete.as_view()),
|
||||
name='workout_delete'),
|
||||
re_path(r'^garmin/summaries/',views.garmin_summaries_view,name='garmin_summaries_view'),
|
||||
re_path(r'^garmin/files/',views.garmin_newfiles_ping,name='garmin_newfiles_ping'),
|
||||
re_path(r'^garmin/activities/',views.garmin_details_view,name='garmin_details_view'),
|
||||
re_path(r'^garmin/deregistration/',views.garmin_deregistration_view,name='garmin_deregistration_view'),
|
||||
# re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/delete/$',login_required(
|
||||
|
||||
@@ -1050,11 +1050,11 @@ def garmin_newfiles_ping(request):
|
||||
try:
|
||||
garmintoken = file['userAccessToken']
|
||||
try:
|
||||
r = Rower.objects.get(garmintoken=garmintoken
|
||||
)
|
||||
r = Rower.objects.get(garmintoken=garmintoken)
|
||||
callbackURL = file['callbackURL']
|
||||
starttime = file['startTimeInSeconds']
|
||||
job = get_garmin_file(r,callbackURL,starttime)
|
||||
fileType = file['fileType']
|
||||
job = garmin_stuff.get_garmin_file(r,callbackURL,starttime,fileType)
|
||||
except Rower.DoesNotExist:
|
||||
pass
|
||||
except KeyError:
|
||||
|
||||
@@ -4624,6 +4624,7 @@ def workout_upload_api(request):
|
||||
q = request.POST
|
||||
post_data = {k: q.getlist(k) if len(q.getlist(k))>1 else v for k, v in q.items()}
|
||||
|
||||
|
||||
# only allow local host
|
||||
hostt = request.get_host().split(':')
|
||||
if hostt[0] not in ['localhost','127.0.0.1','dev.rowsandall.com','rowsandall.com']:
|
||||
@@ -4716,6 +4717,7 @@ def workout_upload_api(request):
|
||||
message = {'status':'false','message':'unable to process file: '+message}
|
||||
else:
|
||||
message = {'status': 'false', 'message': 'unable to process file'}
|
||||
print(message)
|
||||
return JSONResponse(status=400,data=message)
|
||||
if id == -1:
|
||||
message = {'status': 'true', 'message':message}
|
||||
|
||||
Reference in New Issue
Block a user