Private
Public Access
1
0

more code for garmin files

This commit is contained in:
Sander Roosendaal
2020-07-08 15:01:01 +02:00
parent 3bff06abb5
commit c1803ed4a9
3 changed files with 45 additions and 11 deletions

View File

@@ -48,6 +48,8 @@ from rowsandall_app.settings_dev import SITE_URL as SITE_URL_DEV
from rowsandall_app.settings import PROGRESS_CACHE_SECRET
from rowsandall_app.settings import SETTINGS_NAME
from rowsandall_app.settings import workoutemailbox
from rowsandall_app.settings import UPLOAD_SERVICE_SECRET, UPLOAD_SERVICE_URL
import pandas as pd
@@ -678,6 +680,36 @@ def handle_getagegrouprecords(self,
return 1
@app.task(bind=True)
def get_garmin_file(client_id,client_secret,garmintoken,garminrefreshtoken,userid,url,filetype):
garmin = OAuth1Session(client_id,
client_secret=client_secret,
resource_owner_key=garmintoken,
resource_owner_secret=garminrefreshtoken,
)
filename = 'media/{code}_{id}.'.format(
code = uuid4().hex[:16],
id = userid
)+filetype
response = garmin.get(url, stream=True)
if response.status_code == 200:
with open(filename, 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
uploadoptions = {
'secret':UPLOAD_SERVICE_SECRET,
'user':userid,
'file': filename,
'title': 'Import from Garmin File'
}
response = requests.post(UPLOAD_SERVICE_URL,data=uploadoptions)
del response
return 1
@app.task(bind=True)
def long_test_task(self,aantal,debug=False,job=None,session_key=None):