not really importing the steps correctly
This commit is contained in:
@@ -322,30 +322,23 @@ class IntervalsIntegration(SyncIntegration):
|
||||
}
|
||||
|
||||
# first get the folders - we need the folder id for the next call
|
||||
url = self.oauth_data['base_url'] + 'athlete/0/folders'
|
||||
url = self.oauth_data['base_url'] + 'athlete/0/events?category=WORKOUT'
|
||||
response = requests.get(url, headers=headers)
|
||||
if response.status_code != 200:
|
||||
return []
|
||||
|
||||
data = response.json()
|
||||
# get all elements in the list where start_date_local is not None
|
||||
folders = [x for x in data if x['start_date_local']]
|
||||
for plan in folders:
|
||||
plan_start_date = arrow.get(plan['start_date_local']).datetime
|
||||
for session in plan["children"]:
|
||||
session["date"] = (plan_start_date+timedelta(days=session["day"])).date()
|
||||
|
||||
return folders
|
||||
return data
|
||||
|
||||
def get_plannedsession(self, id, *args, **kwargs):
|
||||
_ = self.open()
|
||||
r = self.rower
|
||||
|
||||
url = self.oauth_data['base_url'] + 'athlete/0/workouts/' + str(id)
|
||||
url = self.oauth_data['base_url'] + 'athlete/0/events/' + str(id)
|
||||
headers = {
|
||||
'Authorization': 'Bearer ' + r.intervals_token,
|
||||
}
|
||||
|
||||
response = requests.get(url, headers=headers)
|
||||
|
||||
if response.status_code != 200:
|
||||
@@ -354,6 +347,19 @@ class IntervalsIntegration(SyncIntegration):
|
||||
|
||||
data = response.json()
|
||||
|
||||
# get file from athlete/0/events/{id}/downloadfit
|
||||
url = self.oauth_data['base_url'] + 'athlete/0/events/' + str(id) + '/downloadfit'
|
||||
response = requests.get(url, headers=headers)
|
||||
if response.status_code != 200:
|
||||
dologging('intervals.icu.log', response.text)
|
||||
return 0
|
||||
|
||||
filename = 'media/planned_' + str(id) + '.fit'
|
||||
with open(filename, 'wb') as f:
|
||||
f.write(response.content)
|
||||
|
||||
data['fitfile'] = filename
|
||||
|
||||
return data
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
{% block main %}
|
||||
<h1>Sessions on Intervals.icu</h1>
|
||||
{% if folders %}
|
||||
{% if sessions %}
|
||||
<ul class="main-content">
|
||||
<li class="grid_4">
|
||||
<form enctype="multipart/form-data" method="post">
|
||||
@@ -16,7 +16,6 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Import</th>
|
||||
<th>Plan</th>
|
||||
<th>Date</th>
|
||||
<th>Description</th>
|
||||
<th>Type</th>
|
||||
@@ -24,20 +23,17 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for folder in folders %}
|
||||
{% for session in folder.children %}
|
||||
{% for session in sessions %}
|
||||
<tr>
|
||||
<td>
|
||||
<input type="checkbox" name="session" value="{{ session.id }}">
|
||||
</td>
|
||||
<td>{{ folder.name }}</td>
|
||||
<td>{{ session.date }}</td>
|
||||
<td>{{ session.start_date_local }}</td>
|
||||
<td>{{ session.description }}</td>
|
||||
<td>{{ session.type }}</td>
|
||||
<td>{{ session.icu_training_load }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
@@ -699,28 +699,33 @@ def plannedsession_intervalsimport_view(request, message="", userid=0):
|
||||
sessions_list = integration.get_plannedsessions_list()
|
||||
|
||||
if request.method == 'POST': # pragma: no cover
|
||||
try:
|
||||
tdict = dict(request.POST.lists())
|
||||
print(tdict)
|
||||
ids = tdict['session']
|
||||
sessionids = [int(id) for id in ids]
|
||||
for sessionid in sessionids:
|
||||
try:
|
||||
_ = integration.get_plannedsession(sessionid)
|
||||
except NoTokenError:
|
||||
pass
|
||||
messages.info(
|
||||
request,
|
||||
'Your Intervals.icu planned sessions will be imported in the background.'
|
||||
' It may take a few minutes before they appear.')
|
||||
tdict = dict(request.POST.lists())
|
||||
sessionids = [id for id in tdict['session']]
|
||||
for sessionid in sessionids:
|
||||
sessiondata = integration.get_plannedsession(sessionid)
|
||||
if sessiondata:
|
||||
ps = PlannedSession(
|
||||
name=sessiondata['name'],
|
||||
comment=sessiondata['description'],
|
||||
startdate=arrow.get(sessiondata['start_date_local']).datetime,
|
||||
enddate=arrow.get(sessiondata['end_date_local']).datetime,
|
||||
preferreddate=arrow.get(sessiondata['start_date_local']).datetime,
|
||||
sessionsport=mytypes.intervalsmappinginv[sessiondata['type']],
|
||||
sessiontype='session',
|
||||
intervals_icu_id=sessiondata['id'],
|
||||
manager=request.user,
|
||||
fitfile=sessiondata['fitfile'],
|
||||
)
|
||||
ps.save()
|
||||
ps.rower.add(r)
|
||||
ps.update_steps()
|
||||
url = reverse('plannedsessions_view')
|
||||
return HttpResponseRedirect(url)
|
||||
except KeyError:
|
||||
pass
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
|
||||
return render(request, 'intervals_list_import.html',
|
||||
{
|
||||
'folders': sessions_list,
|
||||
'sessions': sessions_list,
|
||||
'rower': r,
|
||||
'active': 'nav-plans',
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user