-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.py
80 lines (70 loc) · 2.19 KB
/
server.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import re
from function import *
import user
import config
import problem
import spider
from flask import Flask
from flask import request
from flask import render_template
app = Flask(__name__)
config.init()
from config import config
user_set = spider.get_user_set()
name_set = spider.get_problem_list()
@app.route('/api/download_user_set', methods=['POST'])
def download_user_set():
global user_set
user_set = spider.get_user_set()
return ''
@app.route('/api/download_problem_name', methods=['POST'])
def download_problem_name():
global name_set
name_set = spider.download_problem_list()
return ''
@app.route('/api/delete_problem', methods=['POST'])
def delete_problem():
global problem_set
problem.delete(int(request.form['index']))
problem_set = problem.load()
return ''
@app.route('/api/add_problem', methods=['POST'])
def add_problem():
content = request.form['content']
for it in content.split('\n'):
if 'UOJ' in it or 'uoj' in it:
id = re.findall(r'[0-9]+', it)
if len(id) == 1:
problem.append(Problem('UOJ #' + id[0]))
elif 'LOJ' in it or 'loj' in it or 'LibreOJ' in it or 'libreoj' in it:
id = re.findall(r'[0-9]+', it)
if len(id) == 1:
problem.append(Problem('LOJ #' + id[0]))
elif 'BZOJ' in it or 'bzoj' in it or 'lydsy' in it:
id = re.findall(r'[0-9]+', it)
if len(id) == 1:
problem.append(Problem('BZOJ #' + id[0]))
return ''
@app.route('/')
def index():
global user_set, name_set, problem_set
problem_set = problem.load()
data = {
'users': [ it.name for it in user_set ],
'lists': [
{
'id': problem.id,
'url': spider.get_url(problem.id),
'name': name_set[problem.id],
'index': problem_set.index(problem),
'status': [
problem.id in user.ac_list
for user in user_set
]
}
for problem in problem_set
]
}
return render_template('index.html', **data)
if __name__ == '__main__':
app.run(port=config['port'])