-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
85 lines (68 loc) · 2.07 KB
/
app.py
File metadata and controls
85 lines (68 loc) · 2.07 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- coding: utf-8 -*-
from flask import Flask, render_template, request
from push_news_to_bot import start_go, dell, data_json, data_lits
import datetime
app = Flask(__name__)
def get_time():
return datetime.datetime.now().strftime('%Y-%m-%d')
def get_txts():
with open('log', 'r') as t:
return len(t.read().splitlines())
@app.route('/', methods=['GET'])
def write_txt():
t1 = []
try:
with open('log', 'r') as t:
for i in t:
t1.append(eval(i))
return render_template('index.html', txt=t1)
except Exception:
return '<a href="./get"><h1>无数据</h1></a>'
@app.route('/get', methods=['GET'])
def get():
try:
start_go()
return render_template('get.html', data=data_lits)
finally:
dell()
@app.route('/api', methods=['GET'])
def api():
try:
start_go()
return str(data_json).replace("'", '"')
finally:
dell()
@app.route('/add', methods=['POST'])
def add():
addTXT, delTXT = [], []
json = request.form.getlist('txt')
with open('log', 'a+') as t:
if get_txts() == 0:
id = 1
else:
id = get_txts() + 1
for i in data_lits:
i = "{}".format(i)
if i not in json:
j = eval(i)
j['px'] = id
new_t = j['title']
j['title'] = new_t.replace("\n", '')
t.write("{}\n".format(j))
addTXT.append(eval(i))
id += 1
else:
delTXT.append(eval(i))
return render_template('add.html', addTXT=addTXT, delTXT=delTXT)
@app.route('/echo', methods=['GET'])
def echo():
t1 = []
try:
with open('log', 'r') as t:
for i in t:
t1.append(eval(i))
return render_template('echo.html', log=t1)
except Exception:
return '<a href="./get"><h1>无数据</h1></a>'
if __name__ == '__main__':
app.run(host="0.0.0.0", port=80)