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