Skip to content

Instantly share code, notes, and snippets.

@HiKat
Last active September 28, 2019 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HiKat/571345df0afaa305df43b8483ebb51aa to your computer and use it in GitHub Desktop.
Save HiKat/571345df0afaa305df43b8483ebb51aa to your computer and use it in GitHub Desktop.
def get_leaderboard(ac_token, segment_id, page_num, per_page):
url = 'https://www.strava.com/api/v3/segments/%d/leaderboard?page=%d&per_page=%d'%(segment_id, page_num, per_page)
return requests.get(url, headers={'Authorization': 'Bearer %s'%ac_token})
def get_whole_leaderboard(ac_token, segment_id, segment_name, per_page=200):
now = datetime.datetime.now(tz=datetime.timezone(datetime.timedelta(hours=+9), 'JST'))
now_str = "%d%d%d_%d%d%d"%(now.year, now.month, now.day, now.hour, now.minute, now.second)
csv_out = 'hoge'
rsp = get_leaderboard(
ac_token=ac_token,
segment_id=segment_id,
page_num=1,
per_page=10
)
entry_count = rsp.json()['entry_count']
page_max = math.ceil(entry_count/float(per_page))
entries = []
for _pg_num in range(1, 1+page_max):
print(segment_name)
print("Page: %d"%_pg_num)
rsp = get_leaderboard(
ac_token=ac_token,
segment_id=segment_id,
page_num=_pg_num,
per_page=per_page
)
entry = rsp.json()['entries']
entries += entry
time.sleep(100000)
entries_df = pd.DataFrame(entries)
entries_df.to_csv(csv_out)
entries_df.head()
@shinichi-a
Copy link

extract py

Is the highlighted area in yellow garbled?
I am sorry if it is our environmental problem.

@HiKat
Copy link
Author

HiKat commented Sep 28, 2019

Thanks for good question! It's a traditional Python formatting for 'print' . See 7.1.4 on https://docs.python.org/3/tutorial/inputoutput.html
This formatting usually run faster than others👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment