Private
Public Access
1
0

faster download of workout types

This commit is contained in:
Sander Roosendaal
2017-04-17 10:36:36 +02:00
parent e4768ee9ce
commit 16ecb0ffa1
3 changed files with 1720 additions and 13 deletions

View File

@@ -14,6 +14,7 @@ import time
import math
from math import sin,cos,atan2,sqrt
import os,sys
import urllib
# Django
from django.shortcuts import render_to_response
@@ -155,7 +156,6 @@ def make_authorization_url(request):
"response_type": "code",
"redirect_uri": UNDERARMOUR_REDIRECT_URI,
}
import urllib
url = "https://www.mapmyfitness.com/v7.1/oauth2/uacf/authorize/" +urllib.urlencode(params)
return HttpResponseRedirect(url)
@@ -316,25 +316,49 @@ def getidfromresponse(response):
return int(id)
def get_typefromid(typeid,user):
def refresh_ua_actlist(user):
r = Rower.objects.get(user=user)
authorizationstring = str('Bearer ' + r.underarmourtoken)
headers = {'Authorization': authorizationstring,
'Api-Key': UNDERARMOUR_CLIENT_KEY,
'user-agent': 'sanderroosendaal',
'Content-Type': 'application/json'}
import urllib
url = "https://api.ua.com/v7.1/activity_type/"+str(typeid)
'Api-Key': UNDERARMOUR_CLIENT_KEY,
'user-agent': 'sanderroosendaal',
'Content-Type': 'application/json'}
url = "https://api.ua.com/v7.1/activity_type/"
response = requests.get(url,headers=headers)
me_json = response.json()
types = me_json["_embedded"]["activity_types"]
w = {int(t["_links"]["self"][0]["id"]):t["name"] for t in types}
wdf = pd.Series(w,name='Name')
wdf.to_csv('static/rigging/ua2.csv',index_label='id',header=True)
return w
try:
activities = pd.read_csv('static/rigging/ua2.csv',index_col='id')
actdict = activities.to_dict()['Name']
except:
actdict = {}
def get_typefromid(typeid,user):
r = Rower.objects.get(user=user)
try:
res = me_json['name']
res = actdict[int(typeid)]
except KeyError:
res = 0
authorizationstring = str('Bearer ' + r.underarmourtoken)
headers = {'Authorization': authorizationstring,
'Api-Key': UNDERARMOUR_CLIENT_KEY,
'user-agent': 'sanderroosendaal',
'Content-Type': 'application/json'}
url = "https://api.ua.com/v7.1/activity_type/"+str(typeid)
response = requests.get(url,headers=headers)
me_json = response.json()
try:
res = me_json['name']
except KeyError:
res = 0
return res
@@ -348,7 +372,6 @@ def get_userid(access_token):
'Api-Key': UNDERARMOUR_CLIENT_KEY,
'user-agent': 'sanderroosendaal',
'Content-Type': 'application/json'}
import urllib
url = "https://api.ua.com/v7.1/user/self"
response = requests.get(url,headers=headers)