Skip to content

Commit b69734f

Browse files
committed
Using POST requests
Fully resolved #5 Creating Release on tag
1 parent 3b5113f commit b69734f

File tree

8 files changed

+148
-98
lines changed

8 files changed

+148
-98
lines changed

.github/workflows/publish.yml

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Publish to PyPI
1+
name: Publish to PyPI and create Release.
22

33
on:
44
push:
@@ -25,3 +25,19 @@ jobs:
2525
uses: pypa/gh-action-pypi-publish@master
2626
with:
2727
password: ${{ secrets.pypi_password }}
28+
build:
29+
name: Create Release
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Checkout code
33+
uses: actions/checkout@v2
34+
- name: Create Release
35+
id: create_release
36+
uses: actions/create-release@v1
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
with:
40+
tag_name: ${{ github.ref }}
41+
release_name: ${{ github.event.head_commit.message }}
42+
draft: false
43+
prerelease: false

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ dist/
22
build/
33
CodeforcesApiPy.egg-info
44
tests/conf.py
5-
tests/__pycache__/
65
.pylintrc
7-
codeforces_api/__pycache__/
6+
__pycache__/

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 VadVergasov ([email protected])
3+
Copyright (c) 2021 VadVergasov ([email protected])
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ anonim_cf_api = codeforces_api.CodeforcesApi() #Unauthorized access to api.
3737
parser = codeforces_api.CodeforcesParser() #Create parser.
3838
```
3939

40+
Wiki
41+
--------
42+
Here is link to the [wiki](https://github.com/VadVergasov/CodeforcesApiPy/wiki) for more details.
43+
4044
Examples
4145
---------
4246

codeforces_api/api_request_maker.py

+13-29
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""
2+
Class for generating request URLs, which includes working with random, unpacking parameters, calculating hashes.
3+
"""
14
import random
25
import time
36
import hashlib
@@ -24,7 +27,7 @@ def __init__(self, api_key=None, secret=None, random_number=1000000):
2427
self.assigned_rand = True
2528
elif random_number < 100000 and random_number > 999999:
2629
raise Exception(
27-
"Non 6-digit number passed as random_number for API Signature",
30+
"The non-6-digit number passed as random_number for API Signature",
2831
random_number,
2932
)
3033
if api_key is None and secret is None:
@@ -35,11 +38,13 @@ def __init__(self, api_key=None, secret=None, random_number=1000000):
3538
self.anonimus = False
3639
self.rand = random_number
3740

38-
def generate_url(self, method_name, **fields):
41+
def generate_request(self, method_name, **fields):
3942
"""
4043
Generates request URL for API.
4144
"""
4245

46+
request_url = "https://codeforces.com/api/" + str(method_name)
47+
4348
if not self.anonimus:
4449

4550
# Renew Rand
@@ -62,31 +67,8 @@ def generate_url(self, method_name, **fields):
6267
api_signature = api_signature[:-1]
6368
api_signature += "#" + str(self.secret)
6469
hashed_signature = hashlib.sha512(api_signature.encode("utf-8"))
65-
66-
request_url = "https://codeforces.com/api/" + str(method_name) + "?"
67-
for i in fields:
68-
request_url += str(i) + "="
69-
if isinstance(fields[i], list):
70-
for j in fields[i]:
71-
request_url += str(j) + ";"
72-
else:
73-
request_url += str(fields[i])
74-
request_url += "&"
75-
request_url += (
76-
"apiSig=" + str(self.rand) + str(hashed_signature.hexdigest())
77-
)
78-
else:
79-
request_url = "https://codeforces.com/api/" + str(method_name) + "?"
80-
for i in fields:
81-
request_url += str(i) + "="
82-
if isinstance(fields[i], list):
83-
for j in fields[i]:
84-
request_url += str(j) + ";"
85-
else:
86-
request_url += str(fields[i])
87-
request_url += "&"
88-
request_url = request_url[:-1]
89-
return request_url
70+
fields["apiSig"] = str(self.rand) + str(hashed_signature.hexdigest())
71+
return {"request_url": request_url, "data": fields}
9072

9173
def check_return_code(self, response):
9274
"""
@@ -110,7 +92,7 @@ def renew_rand(self, random_number=1000000):
11092
random_number = random.randint(100000, 999999)
11193
elif random_number < 100000 and random_number > 999999:
11294
raise Exception(
113-
"Non 6-digit number passed as random_number for renew_rand",
95+
"The non-6-digit number passed as random_number for renew_rand",
11496
random_number,
11597
)
11698

@@ -120,4 +102,6 @@ def get_response(self, request):
120102
self.check_return_code(response)
121103
return response
122104
except json.decoder.JSONDecodeError as error:
123-
raise ValueError("A lot of users, try to reduce number of users in list")
105+
raise ValueError(
106+
"A lot of users, try to reduce the number of users in the list"
107+
)

0 commit comments

Comments
 (0)