Skip to content

Commit 74f0e34

Browse files
committed
Fix regression in move to Python 3. Re-implement #8.
Signed-off-by: Michael Payne <[email protected]>
1 parent 5be078a commit 74f0e34

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

gcexport3.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ def http_req(url, post=None, headers=None):
100100
# print("post: " + str(post) + "request: " + str(request))
101101
response = OPENER.open((request), data=post)
102102

103-
if response.getcode() != 200:
103+
if response.getcode() == 204:
104+
# For activities without GPS coordinates, there is no GPX download (204 = no content).
105+
# Write an empty file to prevent redownloading it.
106+
print('Writing empty file since there was no GPX activity data...')
107+
return ''
108+
elif response.getcode() != 200:
104109
raise Exception('Bad return code (' + str(response.getcode()) + ') for: ' + url)
105110
# print(response.getcode())
106111

@@ -469,11 +474,11 @@ def http_req(url, post=None, headers=None):
469474

470475
CSV_FILE.write(csv_record)
471476

472-
if ARGS.format == 'gpx':
477+
if ARGS.format == 'gpx' and data:
473478
# Validate GPX data. If we have an activity without GPS data (e.g., running on a
474-
# treadmill), Garmin Connect still kicks out a GPX, but there is only activity
475-
# information, no GPS data. N.B. You can omit the XML parse (and the associated log
476-
# messages) to speed things up.
479+
# treadmill), Garmin Connect still kicks out a GPX (sometimes), but there is only
480+
# activity information, no GPS data. N.B. You can omit the XML parse (and the
481+
# associated log messages) to speed things up.
477482
gpx = parseString(data)
478483
if gpx.getElementsByTagName('trkpt'):
479484
print('Done. GPX data saved.')

0 commit comments

Comments
 (0)