export to intervals.icu
This commit is contained in:
@@ -100,10 +100,98 @@ class IntervalsIntegration(SyncIntegration):
|
|||||||
return token
|
return token
|
||||||
|
|
||||||
def createworkoutdata(self, w, *args, **kwargs) -> str:
|
def createworkoutdata(self, w, *args, **kwargs) -> str:
|
||||||
return NotImplemented
|
dozip = kwargs.get('dozip', True)
|
||||||
|
filename = w.csvfilename
|
||||||
|
try:
|
||||||
|
row = rowingdata(csvfile=filename)
|
||||||
|
except IOError: # pragma: no cover
|
||||||
|
data = dataprep.read_df_sql(w.id)
|
||||||
|
try:
|
||||||
|
datalength = len(data)
|
||||||
|
except AttributeError:
|
||||||
|
datalength = 0
|
||||||
|
|
||||||
|
if datalength == 0:
|
||||||
|
data.rename(columns=columndict, inplace=True)
|
||||||
|
_ = data.to_csv(w.csvfilename+'.gz', index_label='index', compression='gzip')
|
||||||
|
|
||||||
|
try:
|
||||||
|
row = rowingdata(csvfile=filename)
|
||||||
|
except IOError: # pragma: no cover
|
||||||
|
return '' # pragma: no cover
|
||||||
|
else:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
tcxfilename = w.csvfilename[:-4] + '.tcx'
|
||||||
|
try:
|
||||||
|
newnotes = w.notes + '\n from'+w.workoutsource+' via rowsandall.com'
|
||||||
|
except TypeError:
|
||||||
|
newnotes = 'from'+w.workoutsource+' via rowsandall.com'
|
||||||
|
|
||||||
|
row.exporttotcx(tcxfilename, notes=newnotes)
|
||||||
|
if dozip:
|
||||||
|
gzfilename = tcxfilename + '.gz'
|
||||||
|
try:
|
||||||
|
with open(tcxfilename, 'rb') as inF:
|
||||||
|
s = inF.read()
|
||||||
|
with gzip.GzipFile(gzfilename, 'wb') as outF:
|
||||||
|
outF.write(s)
|
||||||
|
try:
|
||||||
|
os.remove(tcxfilename)
|
||||||
|
except WindowsError: # pragma: no cover
|
||||||
|
pass
|
||||||
|
except FileNotFoundError:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
return gzfilename
|
||||||
|
|
||||||
|
return tcxfilename
|
||||||
|
|
||||||
|
|
||||||
def workout_export(self, workout, *args, **kwargs) -> str:
|
def workout_export(self, workout, *args, **kwargs) -> str:
|
||||||
return NotImplemented
|
token = self.open()
|
||||||
|
|
||||||
|
filename = self.createworkoutdata(workout)
|
||||||
|
if not filename:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
params = {
|
||||||
|
'name': workout.name,
|
||||||
|
'description': workout.notes,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
authorizationstring = str('Bearer ' + token)
|
||||||
|
# headers with authorization string and content type multipart/form-data
|
||||||
|
headers = {
|
||||||
|
'Authorization': authorizationstring,
|
||||||
|
}
|
||||||
|
|
||||||
|
url = "https://intervals.icu/api/v1/athlete/{athleteid}/activities".format(athleteid=0)
|
||||||
|
|
||||||
|
with open(filename, 'rb') as f:
|
||||||
|
files = {'file': f}
|
||||||
|
response = requests.post(url, params=params, headers=headers, files=files)
|
||||||
|
|
||||||
|
if response.status_code not in [200, 201]:
|
||||||
|
dologging('intervals.icu.log', response.reason)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
id = response.json()['id']
|
||||||
|
# set workout type to workouttype
|
||||||
|
url = "https://intervals.icu/api/v1/activity/{activityid}".format(activityid=id)
|
||||||
|
|
||||||
|
thetype = mytypes.intervalsmapping[workout.workouttype]
|
||||||
|
response = requests.put(url, headers=headers, json={'type': thetype})
|
||||||
|
if response.status_code not in [200, 201]:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
workout.uploadedtointervals = id
|
||||||
|
workout.save()
|
||||||
|
|
||||||
|
os.remove(filename)
|
||||||
|
|
||||||
|
return id
|
||||||
|
|
||||||
def get_workout_list(self, *args, **kwargs) -> int:
|
def get_workout_list(self, *args, **kwargs) -> int:
|
||||||
url = self.oauth_data['base_url'] + 'athlete/0/activities?'
|
url = self.oauth_data['base_url'] + 'athlete/0/activities?'
|
||||||
|
|||||||
@@ -231,6 +231,20 @@
|
|||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</li>
|
</li>
|
||||||
|
<li id="export-intervals">
|
||||||
|
{% if workout.uploadedtointervals and workout.uploadedtointervals != '0' %}
|
||||||
|
<a href="https://intervals.icu/activities/{{ workout.uploadedtointervals }}">
|
||||||
|
Intervals.icu <i class="fas fa-check"></i>
|
||||||
|
</a>
|
||||||
|
{% elif user.rower.intervals_token == None or user.rower.intervals_token == '' %}
|
||||||
|
<a href="/rowers/me/intervalsauthorize">
|
||||||
|
Connect to Intervals.icu
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
<a href="/rowers/workout/{{ workout.id|encode }}/intervalsuploadw/">
|
||||||
|
Intervals.icu
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
<li id="export-csv">
|
<li id="export-csv">
|
||||||
<a href="/rowers/workout/{{ workout.id|encode }}/emailcsv/">
|
<a href="/rowers/workout/{{ workout.id|encode }}/emailcsv/">
|
||||||
CSV
|
CSV
|
||||||
|
|||||||
Reference in New Issue
Block a user