def DownloadActivity(self, serviceRecord, activity): """ GET Activity as a PWX File URL: https://app.velohero.com/export/activity/pwx/<WORKOUT-ID> Parameters: user = username pass = password PWX export with laps. """ workoutId = activity.ServiceData["workoutId"] logger.debug("Download PWX export with ID: " + str(workoutId)) params = self._add_auth_params({}, record=serviceRecord) res = requests.get(self._urlRoot + "/export/activity/pwx/{}".format(workoutId), headers=self._obligatory_headers, params=params) if res.status_code != 200: if res.status_code == 403: raise APIException("No authorization to download activity with workout ID: {}".format(workoutId), block=True, user_exception=UserException(UserExceptionType.Authorization, intervention_required=True)) raise APIException("Unable to download activity with workout ID: {}".format(workoutId)) activity = PWXIO.Parse(res.content, activity) return activity
def UploadActivity(self, svcRecord, activity): pwxdata = PWXIO.Dump(activity) params = self._authData(svcRecord) resp = requests.post( "https://www.trainingpeaks.com/TPWebServices/EasyFileUpload.ashx", params=params, data=pwxdata.encode("UTF-8")) if resp.text != "OK": raise APIException("Unable to upload activity response " + resp.text + " status " + str(resp.status_code))
def DownloadActivity(self, svcRecord, activity): params = self._authData(svcRecord) params.update({ "workoutIds": activity.ServiceData["WorkoutID"], "personId": svcRecord.ExternalID }) resp = requests.get( "https://www.trainingpeaks.com/tpwebservices/service.asmx/GetExtendedWorkoutsForAccessibleAthlete", params=params) activity = PWXIO.Parse(resp.content, activity) return activity
def DownloadActivity(self, svcRecord, activity): params = self._authData(svcRecord) params.update({"workoutIds": activity.ServiceData["WorkoutID"], "personId": svcRecord.ExternalID}) resp = requests.get("https://www.trainingpeaks.com/tpwebservices/service.asmx/GetExtendedWorkoutsForAccessibleAthlete", params=params) activity = PWXIO.Parse(resp.content, activity) activity.GPS = False flat_wps = activity.GetFlatWaypoints() for wp in flat_wps: if wp.Location and wp.Location.Latitude and wp.Location.Longitude: activity.GPS = True break return activity
def UploadActivity(self, svcRecord, activity): pwxdata_gz = BytesIO() with gzip.GzipFile(fileobj=pwxdata_gz, mode="w") as gzf: gzf.write(PWXIO.Dump(activity).encode("utf-8")) headers = self._apiHeaders(svcRecord) headers.update({"Content-Type": "application/json"}) data = { "UploadClient": "tapiriik", "Filename": "tap-%s.pwx" % activity.UID, "SetWorkoutPublic": not activity.Private, # NB activity notes and name are in the PWX. "Data": base64.b64encode(pwxdata_gz.getvalue()).decode("ascii") } resp = requests.post(TRAININGPEAKS_API_BASE_URL + "/v1/file", data=json.dumps(data), headers=headers) if resp.status_code != 200: raise APIException("Unable to upload activity response " + resp.text + " status " + str(resp.status_code)) return resp.json()[0]["Id"]