Private
Public Access
1
0

strava import now time based

This commit is contained in:
Sander Roosendaal
2017-03-09 23:47:24 +01:00
parent 71bded30c0
commit 1e5d0a0b83

View File

@@ -139,6 +139,7 @@ def get_strava_workout(user,stravaid):
else: else:
# ready to fetch. Hurray # ready to fetch. Hurray
fetchresolution = 'high' fetchresolution = 'high'
series_type = 'time'
authorizationstring = str('Bearer ' + r.stravatoken) authorizationstring = str('Bearer ' + r.stravatoken)
headers = {'Authorization': authorizationstring, headers = {'Authorization': authorizationstring,
'user-agent': 'sanderroosendaal', 'user-agent': 'sanderroosendaal',
@@ -150,17 +151,18 @@ def get_strava_workout(user,stravaid):
workoutsummary['timezone'] = "Etc/UTC" workoutsummary['timezone'] = "Etc/UTC"
startdatetime = workoutsummary['start_date'] startdatetime = workoutsummary['start_date']
url = "https://www.strava.com/api/v3/activities/"+str(stravaid)+"/streams/cadence?resolution="+fetchresolution url = "https://www.strava.com/api/v3/activities/"+str(stravaid)+"/streams/cadence?resolution="+fetchresolution+"&series_type="+series_type
spmjson = requests.get(url,headers=headers) spmjson = requests.get(url,headers=headers)
url = "https://www.strava.com/api/v3/activities/"+str(stravaid)+"/streams/heartrate?resolution="+fetchresolution url = "https://www.strava.com/api/v3/activities/"+str(stravaid)+"/streams/heartrate?resolution="+fetchresolution+"&series_type="+series_type
hrjson = requests.get(url,headers=headers) hrjson = requests.get(url,headers=headers)
url = "https://www.strava.com/api/v3/activities/"+str(stravaid)+"/streams/time?resolution="+fetchresolution url = "https://www.strava.com/api/v3/activities/"+str(stravaid)+"/streams/time?resolution="+fetchresolution+"&series_type="+series_type
print url
timejson = requests.get(url,headers=headers) timejson = requests.get(url,headers=headers)
url = "https://www.strava.com/api/v3/activities/"+str(stravaid)+"/streams/velocity_smooth?resolution="+fetchresolution url = "https://www.strava.com/api/v3/activities/"+str(stravaid)+"/streams/velocity_smooth?resolution="+fetchresolution+"&series_type="+series_type
velojson = requests.get(url,headers=headers) velojson = requests.get(url,headers=headers)
url = "https://www.strava.com/api/v3/activities/"+str(stravaid)+"/streams/distance?resolution="+fetchresolution url = "https://www.strava.com/api/v3/activities/"+str(stravaid)+"/streams/distance?resolution="+fetchresolution+"&series_type="+series_type
distancejson = requests.get(url,headers=headers) distancejson = requests.get(url,headers=headers)
url = "https://www.strava.com/api/v3/activities/"+str(stravaid)+"/streams/latlng?resolution="+fetchresolution url = "https://www.strava.com/api/v3/activities/"+str(stravaid)+"/streams/latlng?resolution="+fetchresolution+"&series_type="+series_type
latlongjson = requests.get(url,headers=headers) latlongjson = requests.get(url,headers=headers)
try: try:
@@ -173,18 +175,19 @@ def get_strava_workout(user,stravaid):
return (0,"something went wrong with the Strava import") return (0,"something went wrong with the Strava import")
try: try:
spm = np.array( spmjson.json()[1]['data']) print spmjson.json()
except IndexError: spm = np.array(spmjson.json()[1]['data'])
except:
spm = np.zeros(nr_rows) spm = np.zeros(nr_rows)
try: try:
hr = np.array(hrjson.json()[1]['data']) hr = np.array(hrjson.json()[1]['data'])
except IndexError: except IndexError,KeyError:
hr = np.zeros(nr_rows) hr = np.zeros(nr_rows)
try: try:
velo = np.array(velojson.json()[1]['data']) velo = np.array(velojson.json()[1]['data'])
except IndexError: except IndexError,KeyError:
velo = np.zeros(nr_rows) velo = np.zeros(nr_rows)
dt = np.diff(t).mean() dt = np.diff(t).mean()
@@ -195,7 +198,7 @@ def get_strava_workout(user,stravaid):
try: try:
lat = coords[:,0] lat = coords[:,0]
lon = coords[:,1] lon = coords[:,1]
except IndexError: except IndexError,KeyError:
lat = np.zeros(len(t)) lat = np.zeros(len(t))
lon = np.zeros(len(t)) lon = np.zeros(len(t))