vadvergasov / codeforcesapipy Goto Github PK
View Code? Open in Web Editor NEWImplementation of https://codeforces.com API
License: GNU General Public License v3.0
Implementation of https://codeforces.com API
License: GNU General Public License v3.0
Describe the bug
I installed the package into a virtual environment and proceeded to attempt the following code:
import codeforces_api
import json
SECRETS = json.load(open("secret.json"))
cf_api = codeforces_api.CodeforcesApi(api_key = SECRETS["key"], secret = SECRETS["secret"])
print(cf_api.contest_list(gym = True))
which of course raised the error
Traceback (most recent call last):
File "/root/lumonike/cf_api/main.py", line 8, in <module>
print(cf_api.contest_list(gym = True))
File "/root/lumonike/cf_api/env/lib/python3.10/site-packages/codeforces_api/api_requests.py", line 112, in contest_list
for contest in self._make_request(
File "/root/lumonike/cf_api/env/lib/python3.10/site-packages/codeforces_api/api_requests.py", line 49, in _make_request
request_data = self.generate_request(method, **payload)
File "/root/lumonike/cf_api/env/lib/python3.10/site-packages/codeforces_api/api_request_maker.py", line 71, in generate_request
api_signature += requests.urllib3.request.urlencode(fields, safe=";")
AttributeError: 'function' object has no attribute 'urlencode'
To Reproduce
Expected behavior
The error mentioned above will be raised
Environment:
Possible Solution
I believe switching line 71 of api_request_maker.py: api_signature += requests.urllib3.request.urlencode(fields, safe=";")
into
api_signature += urlencode(fields, safe=";")
with the addition of this module from urllib.parse import urlencode
completely solve this issue.
To support the use-cases in the project https://github.com/nileshsah/harwest-tool, it'll be great to have additional APIs to support:
(1) Getting a count of the total number of submission-page for a user
Could be achieved by scraping the count from the user submissions page, example
def get_submissions_page_count(self):
base_url = "https://codeforces.com/submissions/" + self.user
sub_soup = self.__get_content_soup(base_url)
pages = sub_soup.findAll('span', attrs={'class': 'page-index'})
return int(pages[-1].find('a').text)
(2) Getting the tags for a given problem Id
Even though it's possible to get the tags for a problem via the Codeforces API, it lacks the tag for the rating of the problem which would be quite crucial to have, and hence scraping might be the only viable option. Example,
def get_contest_tags(self, problem_url):
con_soup = self.__get_content_soup(problem_url)
span_tags = con_soup.findAll('span', attrs={'class': 'tag-box'})
return [x.text.strip() for x in span_tags]
I think adding a Wiki for usage instructions would make the library a lot more accessible.
(I would like to volunteer myself)
Would be cool to add a parser function similar to get_solution
, but for mashup contests created in gym.
Implementation should be similar, except for /gym/
in the url path
def get_gym_solution(self, contest_id, submit_id):
solutionPage = self.session.get(
"https://codeforces.com/gym/"
+ str(contest_id)
+ "/submission/"
+ str(submit_id)
)
if int(solutionPage.status_code) != 200:
raise Exception("Returned not OK code " + str(solutionPage))
tree2 = html.fromstring(solutionPage.text)
code = tree2.xpath("//pre[@id='program-source-text']/text()")
if len(code) == 0:
raise ValueError("Incorrect contest_id or submit_id " + str(code))
return code[0].replace("\r", "")
or just add one more parameter to get_solution
with default value gym=False
Describe the bug
Codeforces have updated their API and added new parameter asManager
to the context.status
endpoint
https://codeforces.com/apiHelp/methods#contest.status
To Reproduce
Steps to reproduce the behavior:
codeforces_api.CodeforcesApi
objectCodeforcesApi.contest_status
method with parameter asManager=True
Expected behavior
Method should work as expected and forward the argument to codeforces webapi
Dependabot couldn't authenticate with https://pypi.python.org/simple/.
You can provide authentication details in your Dependabot dashboard by clicking into the account menu (in the top right) and selecting 'Config variables'.
Describe the bug
There is a typo in the following line:
CodeforcesApiPy/codeforces_api/types.py
Line 94 in 7a950d2
As a result, max_rating
always gets set to None
Corrected version:
max_rating = obj.get("maxRating"))
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.