def get_club(club): """ Get club information from database or strava. """ try: return Club.get(strava_id=club) except Club.DoesNotExist: return fetch_club(club)
def fetch_club(club): """ Fetch and store club information and members from strava. """ data = load_json('http://app.strava.com/api/v1/clubs/%s/members' % club) instance = Club.get_or_create(strava_id=club).values_from_dict(data['club'], {'id': 'strava_id'}) instance.save() fetch_athletes(club, data=data) return instance
def render_template(*args, **kwargs): kwargs.update({ 'clubs': Club.all_augmented(), 'club': kwargs.get('club') or (session.get('club_id') and get_club(session.get('club_id'))) }) return flask_render_template(*args, **kwargs)
def update(): for club in Club.all(): print "Updating: ", club.strava_id update_club(club)