Skip to content

Commit 1b03979

Browse files
committed
removed requests as dependency
- network request are now 50% faster (I am speed) - updated demo code - add tracker in setup
1 parent 0a42adc commit 1b03979

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

coderunner/coderunner.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
====================================
44
The core module of CodeRunner
55
"""
6+
import json
67
import os
7-
8-
import requests
8+
import urllib.parse
9+
import urllib.request
910

1011
# language IDs on judge0, see Documentation
1112
languages = {"C++": 10, "Java": 27, "Python": 34, "C": 4, "Bash": 1}
@@ -87,8 +88,10 @@ def __readStatus(self, token: str):
8788
Check Submission status
8889
"""
8990
while True:
90-
req = requests.get(API_URL + token["token"] + FIELDS)
91-
self.__response = req.json()
91+
req = urllib.request.urlopen(API_URL + token["token"] + FIELDS)
92+
req = req.read()
93+
94+
self.__response = json.loads(req.decode("utf-8"))
9295
self.__memory = self.__response["memory"]
9396
self.__time = self.__response["time"]
9497
status = self.__response["status"]["description"]
@@ -108,8 +111,11 @@ def __submit(self):
108111
api_params["language_id"] = self.language_id
109112
api_params["source_code"] = self.source
110113

111-
res = requests.post(API_URL, data=api_params)
112-
token = res.json()
114+
post_data = urllib.parse.urlencode(api_params).encode("ascii")
115+
req = urllib.request.urlopen(API_URL, post_data)
116+
req = req.read()
117+
token = json.loads(req.decode("utf-8"))
118+
113119
return token
114120

115121
def getSubmissionDate(self):

demo.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,6 @@
1010
# run the code
1111
r.run()
1212

13-
# get Submission status
14-
print("Status : " + r.getStatus())
15-
16-
r.run()
17-
18-
# get Submission status
19-
print("Status : " + r.getStatus())
20-
21-
r.run()
22-
23-
# get Submission status
2413
print("Status : " + r.getStatus())
2514

2615
# check if any error occured

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"Source Code": "https://github.com/codeclassroom/CodeRunner",
2020
"Funding": "https://www.patreon.com/bePatron?u=18082750",
2121
"Say Thanks!": "https://github.com/codeclassroom/CodeRunner/issues/new?assignees=&labels=&template=---say-thank-you.md&title=",
22+
'Tracker': "https://github.com/codeclassroom/CodeRunner/issues",
2223
},
2324
packages=setuptools.find_packages(),
2425
install_requires=[

0 commit comments

Comments
 (0)