-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathweb_server.py
44 lines (35 loc) · 1.35 KB
/
web_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
from flask import Flask,request,send_file
from wakeonlan import send_magic_packet
from pathlib import Path
import os.path,time
import convert,conf
app = Flask(__name__)
@app.route('/')
def hello_world():
if request.method == 'GET':
print(1)
return 'hello world'
#-----------------------------------------#
@app.route('/clash_convert/<group_name>/')
def clash_convert(group_name):
print(group_name)
convert_file = Path('convert_rules/'+str(group_name.split(',')) + '.yaml')
if convert_file.is_file():
edittime = os.path.getmtime(convert_file)#获取文件修改时间
if time.time()-edittime > 120:#运行间隔
try:
convert.run(group_name.split(','))
except:
return '转换失败'
return send_file('convert_rules/'+str(group_name.split(',')) + '.yaml',as_attachment=True)
else:
return send_file('convert_rules/'+str(group_name.split(',')) + '.yaml',as_attachment=True)
else:
try:
convert.run(group_name.split(','))
except:
return '转换失败'
return send_file('convert_rules/'+str(group_name.split(',')) + '.yaml', as_attachment=True)
#-----------------------------------------#
if __name__=='__main__':
app.run(host='0.0.0.0',port=5000)