本文整理汇总了Python中stravalib.client.Client.get_segment_leaderboard方法的典型用法代码示例。如果您正苦于以下问题:Python Client.get_segment_leaderboard方法的具体用法?Python Client.get_segment_leaderboard怎么用?Python Client.get_segment_leaderboard使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stravalib.client.Client
的用法示例。
在下文中一共展示了Client.get_segment_leaderboard方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_segment_leaderboard [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")
示例2: str
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_segment_leaderboard [as 别名]
if "Not Found" in e.message:
cl.sql('DELETE FROM wbstrava WHERE segment_id= ' + str(id))
print("Deleted Strava ID: {}".format(id))
else:
print("Something's wrong with Strava ID: {}".format(id))
## get list of segments already in CartoDB
queryResult = cl.sql('select segment_id from wbstrava')
currentSegments = [x['segment_id'] for x in queryResult['rows']]
now = datetime.datetime.now()
weekAgo = now + datetime.timedelta(days=-7)
for segment in currentSegments:
weekEfforts = client.get_segment_efforts(segment, start_date_local=weekAgo, end_date_local=now)
weekEffortsTimes = [i.moving_time.seconds for i in weekEfforts]
try:
leaderboard = client.get_segment_leaderboard(segment, top_results_limit=100)
leaderboardTimes = [x.moving_time.seconds for x in leaderboard if x.rank <= 100]
# print('Updated {} with {} efforts and {} leaderboard entries'.format(segment, len(weekEffortsTimes), leaderboard.effort_count))
except:
# cl.sql('DELETE FROM wbstrava WHERE segment_id=' + str(segment))
# print('Deleted: {}'.format(client.get_segment(segment).name))
print('Couldn\'t update: {}'.format(client.get_segment(segment).name))
if len(weekEffortsTimes) and len(leaderboardTimes):
segmentMean = np.divide(np.mean(leaderboardTimes), np.mean(weekEffortsTimes)).astype('str')
else:
segmentMean = '0'
cl.sql('UPDATE wbstrava SET ratio = ' + segmentMean + ' WHERE segment_id=' + str(segment))
cl.sql('UPDATE wbstrava SET count = ' + str(len(weekEffortsTimes)) + ' WHERE segment_id=' + str(segment))
time.sleep(0.25)
示例3: print
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_segment_leaderboard [as 别名]
# get athlete activities
activities = client.get_activities(limit=200) # 3
print("number of activities returned", str(len(list(activities))))
# per activity, get segment efforts
for activity in activities:
segment_efforts = client.get_activity(activity.id).segment_efforts # 4
# per segment effort
for segment in segment_efforts:
mysegments[segment.segment.id] = segment.segment # save to db
# check if segment leaderboard contains any friends
for key, segment in mysegments.iteritems():
leaderboard = client.get_segment_leaderboard(key, following=True).entries # 12
# get friend with time < athlete time
for person in leaderboard:
if person.athlete_id == 1869056:
me = person
index = leaderboard.index(me)
if index > 0:
other = leaderboard[index - 1]
data = {}
data['segment_name'] = segment.name
data['person_ahead'] = other.athlete_name
data['distance'] = str(unithelper.miles(segment.distance))
data['my_elapsed_time'] = str(me.elapsed_time)
# data['my_moving_time'] = str(me.moving_time)
data['their_elapsed_time'] = str(other.elapsed_time)