Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if not os.path.isfile(gpxfile):
logger.warning("No file found for " + gpxfile + "!")
return False
logger.debug("Uploading " + gpxfile)
try:
upload = client.upload_activity(
activity_file = open(gpxfile,'r'),
data_type = 'gpx',
private = False,
description = notes,
activity_type = strava_activity_type
)
except exc.ActivityUploadFailed as err:
errStr = str(err)
# deal with duplicate type of error, if duplicate then continue with next file, else stop
if errStr.find('duplicate of activity'):
archive_file(gpxfile)
logger.debug("Duplicate File " + gpxfile)
return True
else:
logger.error("Another ActivityUploadFailed error: {}".format(err))
exit(1)
except ConnectionError as err:
logger.error("No Internet connection: {}".format(err))
exit(1)
logger.info("Upload succeeded.\nWaiting for response...")
def raise_for_error(self):
# FIXME: We need better handling of the actual responses, once those are more accurately documented.
if self.error:
raise exc.ActivityUploadFailed(self.error)
elif self.status == "The created activity has been deleted.":
raise exc.CreatedActivityDeleted(self.status)
Exception raised when the client rate limit has been exceeded
and the time to clear the limit (timeout) has not yet been reached
http://strava.github.io/api/#access
"""
class ActivityUploadFailed(RuntimeError):
pass
class ErrorProcessingActivity(ActivityUploadFailed):
pass
class CreatedActivityDeleted(ActivityUploadFailed):
pass
class TimeoutExceeded(RuntimeError):
pass
class NotAuthenticatedAthlete(AuthError):
"""
Exception when trying to access data which requires an authenticated athlete
"""
pass
except FileNotFoundError:
print('No Strava credentials provided.')
print('You first need to run the script to fetch the credentials')
print('./40-upload_to_strava.py')
return -1
try:
client = Client(access_token=access_token)
print('Uploading {}: '.format(os.path.basename(filename)), end='')
with open(filename, 'rb') as f:
upload = client.upload_activity(
activity_file=f,
data_type='fit',
private=STRAVA_UPLOAD_PRIVATE,
)
except (ActivityUploadFailed, FileNotFoundError) as err:
print('FAILED')
print('Reason:', err)
return -1
print('SUCCESS')
return 0
class RateLimitTimeout(RateLimitExceeded):
"""
Exception raised when the client rate limit has been exceeded
and the time to clear the limit (timeout) has not yet been reached
http://strava.github.io/api/#access
"""
class ActivityUploadFailed(RuntimeError):
pass
class ErrorProcessingActivity(ActivityUploadFailed):
pass
class CreatedActivityDeleted(ActivityUploadFailed):
pass
class TimeoutExceeded(RuntimeError):
pass
class NotAuthenticatedAthlete(AuthError):
"""
Exception when trying to access data which requires an authenticated athlete
"""
pass