Example #1
0
def authorization():
    """
    Method called by Strava (redirect) that includes parameters.
    - state
    - code
    - error
    """
    error = request.args.get('error')
    state = request.args.get('state')
    if error:
        return render_template('authorization_error.html', error=error)
    else:
        code = request.args.get('code')
        client = Client()
        access_token = client.exchange_code_for_token(client_id=app.config['STRAVA_CLIENT_ID'],
                                                      client_secret=app.config['STRAVA_CLIENT_SECRET'],
                                                      code=code)
        # Use the now-authenticated client to get the current athlete
        strava_athlete = client.get_athlete()
        athlete_model = data.register_athlete(strava_athlete, access_token)
        multiple_teams = None
        no_teams = False
        team = None
        try:
            team = data.register_athlete_team(strava_athlete=strava_athlete, athlete_model=athlete_model)
        except bafs.exc.MultipleTeamsError as multx:
            multiple_teams = multx.teams
        except bafs.exc.NoTeamsError:
            no_teams = True


        return render_template('authorization_success.html', athlete=strava_athlete,
                               team=team, multiple_teams=multiple_teams,
                               no_teams=no_teams)
Example #2
0
def authorization():
    """
    Method called by Strava (redirect) that includes parameters.
    - state
    - code
    - error
    """
    error = request.args.get('error')
    state = request.args.get('state')
    if error:
        return render_template('authorization_error.html', error=error)
    else:
        code = request.args.get('code')
        client = Client()
        access_token = client.exchange_code_for_token(client_id=app.config['STRAVA_CLIENT_ID'],
                                                      client_secret=app.config['STRAVA_CLIENT_SECRET'],
                                                      code=code)
        # Use the now-authenticated client to get the current athlete
        strava_athlete = client.get_athlete()
        athlete_model = data.register_athlete(strava_athlete, access_token)
        multiple_teams = None
        no_teams = False
        team = None
        try:
            team = data.register_athlete_team(strava_athlete=strava_athlete, athlete_model=athlete_model)
        except bafs.exc.MultipleTeamsError as multx:
            multiple_teams = multx.teams
        except bafs.exc.NoTeamsError:
            no_teams = True


        return render_template('authorization_success.html', athlete=strava_athlete,
                               team=team, multiple_teams=multiple_teams,
                               no_teams=no_teams)
    def execute(self, options, args):

        sess = db.session

        # We iterate over all of our athletes that have access tokens.  (We can't fetch anything
        # for those that don't.)

        q = sess.query(model.Athlete)
        q = q.filter(model.Athlete.access_token != None)

        for athlete in q.all():
            self.logger.info("Updating athlete: {0}".format(athlete))
            c = data.StravaClientForAthlete(athlete)
            try:
                strava_athlete = c.get_athlete()
                data.register_athlete(strava_athlete, athlete.access_token)
                data.register_athlete_team(strava_athlete, athlete)
            except:
                self.logger.warning("Error registering athlete {0}".format(athlete), exc_info=True)
                # But carry on

        data.disambiguate_athlete_display_names()
Example #4
0
    def execute(self, options, args):

        sess = db.session

        # We iterate over all of our athletes that have access tokens.  (We can't fetch anything
        # for those that don't.)

        q = sess.query(model.Athlete)
        q = q.filter(model.Athlete.access_token != None)

        for athlete in q.all():
            self.logger.info("Updating athlete: {0}".format(athlete))
            c = data.StravaClientForAthlete(athlete)
            try:
                strava_athlete = c.get_athlete()
                data.register_athlete(strava_athlete, athlete.access_token)
                data.register_athlete_team(strava_athlete, athlete)
            except:
                self.logger.warning(
                    "Error registering athlete {0}".format(athlete),
                    exc_info=True)
                # But carry on

        data.disambiguate_athlete_display_names()