def main(): global leader_list client = Client() authorize_url = client.authorization_url( client_id=16694, redirect_uri='http://localhost:8282/authorized') access_token = '1a424f23c2b57360dab45e720a9a45bd0868f299' client.access_token = access_token rex = client.get_athlete(168768) abdul = client.get_athlete(9954274) addison = client.get_athlete(3070847) jd = client.get_athlete(2903427) leaders = client.get_segment_leaderboard(7769406) for leader in leaders: name = (str(leader.athlete_name)) leader_list.append(name) print(leader_list)
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")
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)
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))
# 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)