This repository was archived by the owner on Nov 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
63 lines (45 loc) · 1.4 KB
/
main.py
File metadata and controls
63 lines (45 loc) · 1.4 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from flask import Flask, jsonify, request
from flask_cors import CORS, cross_origin
from waitress import serve
import logging
import api
import asyncio
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
app = Flask('')
app.config['CORS_HEADERS'] = 'Content-Type'
cors = CORS(app)
@app.route('/')
async def home():
return "sup"
@app.route("/getLanguages", methods=["GET"])
async def getLanguages():
response = jsonify(await api.getLanguages())
response.headers.add('Access-Control-Allow-Origin', '*')
return response
@app.route("/execute", methods=["POST"])
async def execute():
lang = request.form["lang"]
code = request.form["code"]
input = request.form["inputs"]
return jsonify(await api.execute(code, lang, input))
@app.route("/submit", methods=["POST"])
async def submit():
lang = request.form["lang"]
code = request.form["code"]
problem = request.form["problem"]
res = []
for i in range(9):
with open(f"p{problem}/in{i+1}.txt") as f:
input = f.read()
out = await api.getOutput(code, lang, input)
out = out.strip()
with open(f"p{problem}/out{i+1}.txt") as f:
output = f.read().strip()
res.append(output == out)
response = jsonify(res)
return response
async def run():
serve(app, host="0.0.0.0", port=8080)
loop = asyncio.new_event_loop()
loop.run_until_complete(run())