forked from JasurbekNURBOYEV/hops
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrex.py
More file actions
44 lines (36 loc) · 1.13 KB
/
rex.py
File metadata and controls
44 lines (36 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# REX.py - code-running stuff is handled here
# the code above just sends request to Rextester API
# and works a little bit on the response, that's it
import requests
import json
def run(lang, code):
languages = {
'python': 24,
'python2': 5,
'python3': 24,
'php': 8
}
try:
if type(lang) == str:
lang = languages[lang]
except:
raise ValueError("Couldn't find the language: {}".format(lang))
class Rex:
errors = result = stats = str
success = bool
def __init__(self, errors=None, result=None, stats=None, success=None):
self.errors = errors
self.result = result
self.stats = stats
self.success = success
url = "https://rextester.com/rundotnet/api"
payload = {"LanguageChoice": lang, "Program": code}
request = requests.post(url, data=payload)
result = request.text
json_obj = json.loads(result)
errors = json_obj['Errors']
result = json_obj['Result']
stats = json_obj['Stats']
success = True if not errors else False
rex = Rex(errors, result, stats, success)
return rex