This repository was archived by the owner on Nov 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
Codeforces - Added contest info #10
Merged
abhijeet-reddy
merged 1 commit into
abhijeet-reddy:master
from
saurabh-prakash:codeforces-contest-info
Dec 31, 2020
Merged
Codeforces - Added contest info #10
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| .idea/ | ||
| __pycache__ | ||
| .DS_Store | ||
| venv/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| import json | ||
| import re | ||
| # DO NOT import this after requests | ||
| import grequests | ||
| import requests | ||
| import os | ||
|
|
||
|
|
@@ -114,7 +116,7 @@ def problems_solved_get(): | |
|
|
||
| categories = problem_solved_section.find_all('article') | ||
|
|
||
| fully_solved = {'count': int(re.findall('\d+', no_solved[0].text)[0])} | ||
| fully_solved = {'count': int(re.findall(r'\d+', no_solved[0].text)[0])} | ||
|
|
||
| if fully_solved['count'] != 0: | ||
| for category in categories[0].find_all('p'): | ||
|
|
@@ -125,7 +127,7 @@ def problems_solved_get(): | |
| fully_solved[category_name].append({'name': prob.text, | ||
| 'link': 'https://www.codechef.com' + prob['href']}) | ||
|
|
||
| partially_solved = {'count': int(re.findall('\d+', no_solved[1].text)[0])} | ||
| partially_solved = {'count': int(re.findall(r'\d+', no_solved[1].text)[0])} | ||
| if partially_solved['count'] != 0: | ||
| for category in categories[1].find_all('p'): | ||
| category_name = category.find('strong').text[:-1] | ||
|
|
@@ -160,16 +162,40 @@ def user_details_get(): | |
| return details | ||
|
|
||
| def __codeforces(self): | ||
| url = 'https://codeforces.com/api/user.info?handles={}'.format(self.__username) | ||
| urls = { | ||
| "user_info": {"url": f'https://codeforces.com/api/user.info?handles={self.__username}'}, | ||
| "user_contests": {"url": f'https://codeforces.com/contests/with/{self.__username}'} | ||
| } | ||
|
|
||
| page = requests.get(url) | ||
|
|
||
| if page.status_code != 200: | ||
| raise UsernameError('User not Found') | ||
| reqs = [grequests.get(item["url"]) for item in urls.values() if item.get("url")] | ||
|
|
||
| details_api = page.json() | ||
| responses = grequests.map(reqs) | ||
|
|
||
| if details_api['status'] != 'OK': | ||
| details_api = {} | ||
| contests = [] | ||
| for page in responses: | ||
| if page.status_code != 200: | ||
| raise UsernameError('User not Found') | ||
| if page.request.url == urls["user_info"]["url"]: | ||
| details_api = page.json() | ||
| elif page.request.url == urls["user_contests"]["url"]: | ||
| soup = BeautifulSoup(page.text, 'html.parser') | ||
| table = soup.find('table', attrs={'class': 'user-contests-table'}) | ||
| table_body = table.find('tbody') | ||
|
|
||
| rows = table_body.find_all('tr') | ||
| for row in rows: | ||
| cols = row.find_all('td') | ||
| cols = [ele.text.strip() for ele in cols] | ||
| contests.append({ | ||
| "Contest": cols[1], | ||
| "Rank": cols[3], | ||
| "Solved": cols[4], | ||
| "Rating Change": cols[5], | ||
| "New Rating": cols[6] | ||
| }) | ||
|
|
||
| if details_api.get('status') != 'OK': | ||
| raise UsernameError('User not Found') | ||
|
|
||
| details_api = details_api['result'][0] | ||
|
|
@@ -186,10 +212,16 @@ def __codeforces(self): | |
| rank = 'Unrated' | ||
| max_rank = 'Unrated' | ||
|
|
||
| details = {'status': 'Success', 'username': self.__username, 'platform': 'Codeforces', | ||
| 'rating': rating, 'max rating': max_rating, 'rank': rank, 'max rank': max_rank} | ||
|
|
||
| return details | ||
| return { | ||
| 'status': 'Success', | ||
| 'username': self.__username, | ||
| 'platform': 'Codeforces', | ||
| 'rating': rating, | ||
| 'max rating': max_rating, | ||
| 'rank': rank, | ||
| 'max rank': max_rank, | ||
| 'contests': contests | ||
| } | ||
|
|
||
| def __spoj(self): | ||
| url = 'https://www.spoj.com/users/{}/'.format(self.__username) | ||
|
|
@@ -365,6 +397,6 @@ def get_details(self, platform): | |
| if __name__ == '__main__': | ||
| ud = UserData('abhijeet_ar') | ||
|
|
||
| ans = ud.get_details('codechef') | ||
| ans = ud.get_details('codeforces') | ||
|
|
||
| print(ans) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ Click==7.0 | |
| Flask==1.1.1 | ||
| Flask-Cors==3.0.8 | ||
| Flask-RESTful==0.3.7 | ||
| grequests==0.6.0 | ||
| gunicorn==20.0.4 | ||
| idna==2.8 | ||
| itsdangerous==1.1.0 | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.