Skip to content

Commit

Permalink
Merge pull request #455 from campbellr/issue448
Browse files Browse the repository at this point in the history
Smashrun: Fetch activities without pagination when doing exhaustive sync
  • Loading branch information
cpfair committed Oct 13, 2018
2 parents 4ccc289 + 4e84b86 commit b09e57c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions requirements.txt
Expand Up @@ -11,5 +11,5 @@ django-pipeline==1.5.1
requests_oauthlib==0.4.0
redis
django-ipware
smashrun-client>=0.2.0
beautifulsoup4
smashrun-client>=0.6.0
beautifulsoup4
13 changes: 7 additions & 6 deletions tapiriik/services/Smashrun/smashrun.py
Expand Up @@ -19,6 +19,10 @@

logger = logging.getLogger(__name__)

# The number of activities to fetch per 'page' when iterating through the
# Smashrun API.
PAGE_COUNT = 20


def handleExpiredToken(f):
"""Handle token expiry during execution of `f`.
Expand Down Expand Up @@ -135,12 +139,9 @@ def RevokeAuthorization(self, serviceRecord):
@handleExpiredToken
def _getActivities(self, serviceRecord, exhaustive=False):
client = self._getClient(serviceRec=serviceRecord)
activities = []
for i, act in enumerate(client.get_activities()):
if not exhaustive and i > 20:
return activities
activities.append(act)
return activities
return list(client.get_activities(
count=None if exhaustive else PAGE_COUNT,
limit=None if exhaustive else PAGE_COUNT))

@handleExpiredToken
def _getActivity(self, serviceRecord, activity):
Expand Down

0 comments on commit b09e57c

Please sign in to comment.