本文整理汇总了Python中stravalib.client.Client.get_athlete方法的典型用法代码示例。如果您正苦于以下问题:Python Client.get_athlete方法的具体用法?Python Client.get_athlete怎么用?Python Client.get_athlete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stravalib.client.Client
的用法示例。
在下文中一共展示了Client.get_athlete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_oauth_token
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_athlete [as 别名]
def check_oauth_token(cls, access_token):
if not access_token:
return False
c = Client()
c.access_token = access_token
try:
c.get_athlete()
except HTTPError:
return False
else:
return True
示例2: get
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_athlete [as 别名]
def get(request):
""" Request -and store- a strava access token. """
client = Client()
# Extract the code from the response
code = request.GET.get('code')
access_token = client.exchange_code_for_token(
client_id=settings.STRAVA_CLIENT_ID,
client_secret=settings.STRAVA_CLIENT_SECRET,
code=code
)
strava_athlete = client.get_athlete()
try:
athlete = Athlete.objects.get(strava_id=strava_athlete.id)
athlete.strava_token = access_token
except Athlete.DoesNotExist:
athlete = Athlete(strava_id=strava_athlete.id, strava_token=access_token)
athlete.save()
cache_key = _get_cache_key(request)
cache.delete(cache_key)
redir_url = '{}?start_date={}&end_date={}'.format(
reverse_lazy('strava-summary'),
_get_start_date(request),
_get_end_date(request)
)
return HttpResponseRedirect(redir_url)
示例3: auth_success
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_athlete [as 别名]
def auth_success(request):
temp_code = request.GET.get('code') # temp auth code
print(temp_code)
client = Client()
token = client.exchange_code_for_token(5928, 'a486a0b19c8d16aef41090371b7726dc510ee4a7', temp_code)
if not athlete.objects.filter(pk=client.get_athlete().id):
new_athlete = athlete(
id = client.get_athlete().id,
firstname = client.get_athlete().firstname,
lastname = client.get_athlete().lastname,
access_token = token
)
new_athlete.save()
data_scraper(after_utc, before_utc, client.get_athlete().id)
result = 'added'
else:
result = 'already exists'
return render(request, 'auth_success.html', {'leaderboard':get_leaderboard(), 'result':result})
示例4: auth
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_athlete [as 别名]
def auth():
try:
code = request.args["code"]
c = Client()
token = c.exchange_code_for_token(app.config['STRAVA_ID'], app.config['STRAVA_SECRET'], code)
except (KeyError, requests.exceptions.HTTPError):
return redirect("/")
session["token"] = c.access_token = token
a = c.get_athlete() # Technically shouldn't be needed as the athlete details are returned in the oauth call
session["athlete"] = {"firstname": a.firstname, "picture": a.profile_medium}
return redirect("/")
示例5: get_user
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_athlete [as 别名]
def get_user(self):
client = Client()
token = self.accessToken()
if token is None:
return None
client.access_token = token
athlete = client.get_athlete()
return dict(first_name=athlete.firstname,
last_name=athlete.lastname,
email=athlete.email)
示例6: get_emails
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_athlete [as 别名]
def get_emails():
email_list = []
athletes = athlete.objects.all()
for each_athlete in athletes: # for each athlete
client = Client(access_token=each_athlete.access_token)
this_athlete_email = client.get_athlete().email
email_list.append(this_athlete_email)
string_of_emails = ""
for value in email_list:
string_of_emails += str(value)
string_of_emails += "; "
print(string_of_emails)
示例7: AddUserToken
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_athlete [as 别名]
def AddUserToken(self, token):
client = Client(token)
athlete = client.get_athlete()
# Simplified logic not to add duplicate user tokens.
# todo: check the user is not in the user token table.
if self.GetMemcacheToken(athlete.id) is None:
rider = UserToken(strava_id=athlete.id, strava_token=token)
rider.put()
memcache.add(self.GetMemcacheKey(athlete.id), token, 60)
return athlete.id
示例8: index
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_athlete [as 别名]
def index(request):
# Get KM cycled from Strava API
from stravalib.client import Client
from stravalib import unithelper
strava = Client(settings.STRAVA_TOKEN)
profile = strava.get_athlete(settings.STRAVA_ID)
cycled = 0
for b in profile.bikes:
cycled += float(b.distance) / 1000
return render_to_response(
'cv/index.html',
locals(),
context_instance=RequestContext(request)
)
示例9: authorized
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_athlete [as 别名]
def authorized():
# get access token to make requests
client = Client()
code = request.args.get('code')
client.access_token = client.exchange_code_for_token(client_id=creds.client_id, client_secret=creds.client_secret, code=code) # add id and secret
# get data
today = datetime.datetime.strptime(str(datetime.date.today()), "%Y-%m-%d")
one_month_ago = today - dateutil.relativedelta.relativedelta(months=1)
athlete = client.get_athlete()
activities = client.get_activities(after=one_month_ago)
rides = toolkit.get_activity_types(activities, 'ride')
runs = toolkit.get_activity_types(activities, 'run')
ride_set = ActivitySet("Rides", rides)
run_set = ActivitySet("Runs", runs)
return render_template('main.html', athlete=athlete, activity_sets=[ride_set, run_set])
示例10: index
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_athlete [as 别名]
def index():
access_token = session.get('access_token')
if access_token is None:
return redirect(url_for('login'))
client = Client(access_token=access_token)
athlete = client.get_athlete() # client.protocol.get('/athletes/your_id')
athlete_id = athlete.id
# bo = 'hi'
# kim = 'yo'
# c = bo + kim
stats_m = client.protocol.get('/athletes/' + str(athlete_id) + '/stats')
stats_mi = {
'run_distance': m_to_mi(stats_m['recent_run_totals']['distance']),
'run_count': stats_m['recent_run_totals']['count'],
'run_elevation': el(stats_m['recent_run_totals']['elevation_gain']),
'run_pace': average_pace(stats_m['recent_run_totals']['distance'], stats_m['recent_run_totals']['moving_time']),
'run_distance_ytd': m_to_mi(stats_m['ytd_run_totals']['distance']),
'run_count_ytd': stats_m['ytd_run_totals']['count'],
'run_elevation_ytd': el(stats_m['ytd_run_totals']['elevation_gain']),
'run_pace_ytd': average_pace(stats_m['ytd_run_totals']['distance'], stats_m['ytd_run_totals']['moving_time']),
'run_distance_all': m_to_mi(stats_m['all_run_totals']['distance']),
'run_count_all': stats_m['all_run_totals']['count'],
'run_elevation_all': el(stats_m['all_run_totals']['elevation_gain']),
'run_pace_all': average_pace(stats_m['all_run_totals']['distance'], stats_m['all_run_totals']['moving_time']),
'ride_distance': m_to_mi(stats_m['recent_ride_totals']['distance']),
'ride_count': stats_m['recent_ride_totals']['count'],
'ride_elevation': el(stats_m['recent_ride_totals']['elevation_gain']),
'ride_speed': average_mph(stats_m['recent_ride_totals']['distance'], stats_m['recent_ride_totals']['moving_time']),
'ride_distance_ytd': m_to_mi(stats_m['ytd_ride_totals']['distance']),
'ride_count_ytd': stats_m['ytd_ride_totals']['count'],
'ride_elevation_ytd': el(stats_m['ytd_ride_totals']['elevation_gain']),
'ride_speed_ytd': average_mph(stats_m['ytd_ride_totals']['distance'], stats_m['ytd_ride_totals']['moving_time']),
'ride_distance_all': m_to_mi(stats_m['all_ride_totals']['distance']),
'ride_count_all': stats_m['all_ride_totals']['count'],
'ride_elevation_all': el(stats_m['all_ride_totals']['elevation_gain']),
'ride_speed_all': average_mph(stats_m['all_ride_totals']['distance'], stats_m['all_ride_totals']['moving_time']),
}
# raise Exception(stats_mi['run_distance'])
return render_template('index.html', athlete=athlete, stats=stats_mi, athlete_id=athlete)
示例11: main
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_athlete [as 别名]
def main():
reload(sys)
sys.setdefaultencoding('utf8')
client = Client(access_token='76824abf6abf903eb3d8b0bde83625135c0be0ec')
athlete = client.get_athlete()
print("Hello, {}. I know your email is {}".format(athlete.firstname, athlete.email))
josh_friends = client.get_athlete_friends(5991862)
print "Starting...."
leaderboard = client.get_segment_leaderboard(2658830,following=True)
print leaderboard[0].athlete_name
friend_colour_dict = {}
friend_colour_file = open('friend_colour.csv')
colourreader = UnicodeDictReader(friend_colour_file)
for line in colourreader:
friend_colour_dict[line["name"]] = line["colour"]
for x in friend_colour_dict:
print str(x).encode("utf8")
示例12: auth
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_athlete [as 别名]
def auth():
try:
code = request.args["code"]
c = Client()
token = c.exchange_code_for_token(app.config['STRAVA_ID'], app.config['STRAVA_SECRET'], code)
except (KeyError, requests.exceptions.HTTPError):
return redirect("/")
session["token"] = c.access_token = token
a = c.get_athlete() # Technically shouldn't be needed as the athlete details are returned in the oauth call
session["athlete"] = {"name": a.firstname, "picture": a.profile_medium, "id": a.id}
# lookup athlete in db
cur = g.db.execute('select * from users where id = {}'.format(a.id))
x = cur.fetchall()
print x
if not x:
# Create the object in the db
cur = g.db.cursor()
cur.execute('insert into users (id, name, picture) values (?, ?, ?)', (a.id, a.firstname, a.profile))
g.db.commit()
cur.close()
return redirect("/")
示例13: print
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_athlete [as 别名]
REAUTH = False
ClientId = "<ClientId_int_here>"
ClientSecret = "<ClientSecret_string_here>"
AccessToken = "<AccessToken_here_if_available>"
clientCode = "<ClientCodeHere>"
meterToMile = 0.000621371
if(REAUTH):
AccessToken = client.exchange_code_for_token(client_id=ClientId,
client_secret=ClientSecret,
code=clientCode)
print(AccessToken)
client = Client(access_token=AccessToken)
athlete = client.get_athlete()
r = open('data.json', 'r')
data = json.load(r)
activities = list(d["id"] for d in data)
r.close()
stravaActivities = client.get_activities()
for activity in stravaActivities:
if (activity.id in activities):
print("Already have this activity!")
continue
a = client.get_activity(activity.id)
if (a.type != "Run"):
print("Activity was a run")
示例14: Client
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_athlete [as 别名]
from stravalib.client import Client
club_id = 24151
client = Client(access_token='250d33ceabfbe833376eb18885e797af14888512')
athlete = client.get_athlete() # Get John's full athlete record
print("Hello, {}. I know your email is {}".format(athlete.firstname, athlete.email))
# "Hello, John. I know your email is [email protected]"
activities = client.get_activities(limit=10)
assert len(list(activities)) == 10
clubs = client.get_athlete_clubs()
icc_members = client.get_club_members(club_id, limit=20)
assert len(list(icc_members)) == 20
club_activities = client.get_club_activities(club_id, limit=20)
assert len(list(club_activities)) == 20
#View activities
#for x in activities:
# print (x)
for x in clubs:
print (x)
for x in icc_members:
print (x)
示例15: datetime
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_athlete [as 别名]
segment_id = 8516849 # 2015 Leeds Abbey Dash
race_time = datetime(2015,11,15)
output_file = 'data/leeds.times.csv'
access_token = "<ACCESS TOKEN>"
client = Client()
client.access_token = access_token
# Get all efforts on the day of the race
efforts = client.get_segment_efforts(segment_id,
start_date_local=race_time,
end_date_local=race_time+timedelta(1))
data = []
data.append(["athlete_id", "sex", "first_name", "last_name", "time"])
print "a"
counter = 0
for effort in efforts:
print counter
counter = counter + 1
time = effort.elapsed_time.seconds
athlete_id = effort.athlete.id
athlete = client.get_athlete(athlete_id)
first_name = re.sub('[^0-9a-zA-Z]+', '', athlete.firstname)
last_name = re.sub('[^0-9a-zA-Z]+', '', athlete.lastname)
data.append([athlete_id, athlete.sex, first_name, last_name, time])
# Write to file
with open(output_file, 'wb') as csv_file:
writer = csv.writer(csv_file)
writer.writerows(data)