-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
44 lines (30 loc) · 903 Bytes
/
main.py
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
#!/usr/bin/env python3
# AgroHack 2021
import time, random, string, asyncio
from quart import *
app = Quart(__name__)
@app.route('/')
async def index():
return await render_template('index.html')
@app.route('/upload', methods=('POST',))
async def upload():
id = str().join(random.choices(string.ascii_lowercase, k=8))
app.complete[id] = (int(time.time()) + 2) # simulate some processing
return id
@app.route('/result')
async def result():
try: id = request.args['id']
except KeyError as ex: return abort(400, ex)
try: t = app.complete[id]
except KeyError as ex: return abort(404, ex)
await asyncio.sleep(t - time.time())
return 'OK'
@app.before_serving
def before_serving():
app.complete = dict()
def main():
app.env = 'development'
app.run('unix', '///tmp/agrohack.sock', debug=True)
if (__name__ == '__main__'): exit(main())
# by InfantemTeam, 2021