now using golang fit server
This commit is contained in:
@@ -15,6 +15,7 @@ import datetime
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from fitparse import FitFile
|
from fitparse import FitFile
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
|
||||||
@@ -544,40 +545,19 @@ def allsundays(startdate,enddate):
|
|||||||
d += datetime.timedelta(days=7)
|
d += datetime.timedelta(days=7)
|
||||||
|
|
||||||
def steps_read_fit(filename,name='',sport='Custom'):
|
def steps_read_fit(filename,name='',sport='Custom'):
|
||||||
fitfile = FitFile(filename,check_crc=False)
|
authorizationstring = 'Bearer '+settings.WORKOUTS_FIT_TOKEN
|
||||||
records = fitfile.messages
|
url = settings.WORKOUTS_FIT_URL
|
||||||
m0 = records[0]
|
headers = {'Authorization':authorizationstring}
|
||||||
typ = m0.fields[0].value
|
|
||||||
if typ != 'workout':
|
response = requests.post(url=url,headers=headers,json={'filename':filename})
|
||||||
raise TypeError("Wrong FIT file type")
|
|
||||||
|
|
||||||
steps = []
|
if response.status_code != 200:
|
||||||
stepmessages = fitfile.get_messages('workout_step')
|
return None
|
||||||
|
|
||||||
steps = []
|
w = response.json()
|
||||||
stepmessages = fitfile.get_messages('workout_step')
|
try:
|
||||||
|
d = w['workout']
|
||||||
for msg in stepmessages:
|
except KeyError:
|
||||||
if msg.name == 'workout_step':
|
return None
|
||||||
step = {}
|
|
||||||
for field in msg.fields:
|
|
||||||
ff = field.as_dict()
|
|
||||||
step[ff['name']] = ff['value']
|
|
||||||
steps.append(step)
|
|
||||||
|
|
||||||
for msg in fitfile.get_messages('workout'):
|
|
||||||
if msg.name == 'workout':
|
|
||||||
for field in msg.fields:
|
|
||||||
ff = field.as_dict()
|
|
||||||
if ff['name'] == 'wkt_name':
|
|
||||||
name = ff['value']
|
|
||||||
if ff['name'] == 'sport':
|
|
||||||
sport = ff['value']
|
|
||||||
|
|
||||||
d = {}
|
|
||||||
d['filename'] = filename
|
|
||||||
d['name'] = name
|
|
||||||
d['steps'] = steps
|
|
||||||
d['sport'] = sport
|
|
||||||
|
|
||||||
return d
|
return d
|
||||||
|
|||||||
@@ -564,6 +564,12 @@ try:
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
CELERY = False
|
CELERY = False
|
||||||
|
|
||||||
|
try:
|
||||||
|
WORKOUTS_FIT_TOKEN = CFG['workouts_fit_token']
|
||||||
|
WORKOUTS_FIT_URL = CFG['workouts_fit_url']
|
||||||
|
except KeyError:
|
||||||
|
WORKOUTS_FIT_TOKEN = 'aapnootmies'
|
||||||
|
WORKOUTS_FIT_URL = 'http://localhost:50053/tojson'
|
||||||
|
|
||||||
# Recaptcha
|
# Recaptcha
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user