Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature : list of Top Coder #16

Open
cs20m002 opened this issue Mar 24, 2021 · 6 comments
Open

feature : list of Top Coder #16

cs20m002 opened this issue Mar 24, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@cs20m002
Copy link

any API to get top coder list from Codechef

@saurabh-prakash
Copy link
Contributor

saurabh-prakash commented Mar 30, 2021

Well, codechef removed its APIs from public access some time back. However, if you're still adamant, you can inspect the ratings page and observe the APIs it hits. One interesting API is https://www.codechef.com/api/ratings/all?sortBy=global_rank&order=asc&page=1&itemsPerPage=20 but it requires x-csrf-token and cookie headers to be present to return you a response. You can get these 2 things:

  1. x-csrf-token: value is returned as a window.csrfToken in html response of codechef ratings/homepage
  2. cookie: use the cookie returned while visiting the above page (by reusing the session)

Here's a Python snippet:

import re
import requests
import json

sess = requests.Session()
res = sess.get('https://www.codechef.com')
match_obj = re.search(r"window\.csrfToken\s*=\s*'(.*?)';", res.text)
token = ''
if match_obj is not None:
    token = match_obj.group(1)
print(token)
res = sess.get('https://www.codechef.com/api/ratings/all?sortBy=global_rank&order=asc&page=1&itemsPerPage=20', headers={'x-csrf-token': token})
print(res.text)

@Abhijeet-AR can decide if we want to add/provide this functionality as a part of this repository.

@saurabh-prakash
Copy link
Contributor

Another method is parsing html table on this page https://www.codechef.com/ratings/all. I, personally, don't like this method though.

@Abhijeet-AR
Copy link
Owner

Well, codechef removed its APIs from public access some time back. However, if you're still adamant, you can inspect the ratings page and observe the APIs it hits. One interesting API is https://www.codechef.com/api/ratings/all?sortBy=global_rank&order=asc&page=1&itemsPerPage=20 but it requires x-csrf-token and cookie headers to be present to return you a response. You can get these 2 things:

  1. x-csrf-token: value is returned as a window.csrfToken in html response of codechef ratings/homepage
  2. cookie: use the cookie returned while visiting the above page (by reusing the session)

Here's a Python snippet:

import re
import requests
import json

sess = requests.Session()
res = sess.get('https://www.codechef.com')
match_obj = re.search(r"window\.csrfToken\s*=\s*'(.*?)';", res.text)
token = ''
if match_obj is not None:
    token = match_obj.group(1)
print(token)
res = sess.get('https://www.codechef.com/api/ratings/all?sortBy=global_rank&order=asc&page=1&itemsPerPage=20', headers={'x-csrf-token': token})
print(res.text)

@Abhijeet-AR can decide if we want to add/provide this functionality as a part of this repository.

That's a really good solution. This repo is to provide user details of competitive coding platforms through an API. But top coders list doesn't fit in the profile. But I'm open to pivot and add more features like this. What are your thoughts @saurabh-prakash? Should we add it as a feature?

@saurabh-prakash
Copy link
Contributor

Depends on demand. If there is not enough demand for this feature, there's always an overhead cost of maintenance.

Let's keep this issue open and observe the number of +1s we get for this feature. We'll take a call (on whether to add or not) at a later date.

@Abhijeet-AR
Copy link
Owner

Sounds good 🙂

@nisarg0
Copy link

nisarg0 commented May 28, 2021

+1

@Abhijeet-AR Abhijeet-AR added the enhancement New feature or request label May 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants