not all activities have FIT files (e.g., manually entered ones)

This commit is contained in:
petergardfjall 2014-11-09 13:56:50 +01:00
parent 35aea411d0
commit aa5de9c4a7
3 changed files with 20 additions and 10 deletions

View File

@ -37,15 +37,16 @@ directory on your machine.
For each activity, these files are stored:
- an activity summary file (JSON)
- an activity summary file (JSON)
- an activity details file (JSON)
- an activity details file (JSON)
- an activity GPX file (XML)
- an activity GPX file (XML)
- an activity TCX file (XML)
- an activity TCX file (XML)
- an activity FIT file (binary)
- an activity FIT file (binary) (if available -- the activity may have
been entered manuall rather than imported from a Garmin device).
All files are written to the same directory (``activities/<timestamp>/``
by default). Each activity file is prefixed by its upload timestamp and its

View File

@ -92,8 +92,9 @@ if __name__ == "__main__":
f.write(activity_gpx)
with codecs.open(tcx_file, encoding="utf-8", mode="w") as f:
f.write(activity_tcx)
with open(fit_file, mode="wb") as f:
f.write(activity_fit)
if activity_fit:
with open(fit_file, mode="wb") as f:
f.write(activity_fit)
except Exception as e:
exc_type, exc_value, exc_traceback = sys.exc_info()
log.error(u"failed with exception: %s", e)

View File

@ -262,22 +262,30 @@ class GarminClient(object):
:returns: The TCX representation of the activity as an XML string.
:rtype: str
"""
response = self.session.get("https://connect.garmin.com/proxy/activity-service-1.3/tcx/course/{}".format(activity_id))
response = self.session.get("http://connect.garmin.com/proxy/activity-service-1.1/tcx/activity/{}?full=true".format(activity_id))
if response.status_code != 200:
raise Exception(u"failed to fetch TCX for activity {}: {}\n{}".format(
activity_id, response.status_code, response.text))
return response.text
def get_activity_fit(self, activity_id):
"""Return a FIT representation for a given activity.
"""Return a FIT representation for a given activity. If the activity
doesn't have a FIT source (for example, if it was entered manually
rather than imported from a Garmin device) a :obj:`None` value is
returned.
:param activity_id: Activity identifier.
:type activity_id: int
:returns: A string with a FIT file for the activity.
:returns: A string with a FIT file for the activity or :obj:`None`
if no FIT source exists for this activity (e.g., entered manually).
:rtype: str
"""
response = self.session.get("https://connect.garmin.com/proxy/download-service/files/activity/{}".format(activity_id))
if response.status_code == 404:
# No FIT source available for activity
return None
if response.status_code != 200:
raise Exception(u"failed to fetch FIT for activity {}: {}\n{}".format(
activity_id, response.status_code, response.text))