-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.py
84 lines (70 loc) · 2.28 KB
/
hello.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
81
82
83
84
from flask import Flask, render_template, request
app = Flask(__name__)
import json
import sys
with open('urllist.txt') as json_file:
urllist = json.load(json_file)
print(urllist)
urllists = json.dumps(urllist)
loaded_urllist = json.loads(urllists)
arrpos = [0]
idcounter = 1
for x in range(len(loaded_urllist["websites"])):
if idcounter != loaded_urllist["websites"][x]["id"]:
arrpos.append(x)
idcounter=idcounter+1
def refresh():
with open('urllist.txt') as json_file:
global urllist
urllist = json.load(json_file)
print(urllist)
global urllists
global loaded_urllist
urllists = json.dumps(urllist)
loaded_urllist = json.loads(urllists)
global arrpos
arrpos = [0]
idcounter = 1
for x in range(len(loaded_urllist["websites"])):
if idcounter != loaded_urllist["websites"][x]["id"]:
arrpos.append(x)
idcounter=idcounter+1
def arrayToJson(array):
list1 = {}
list1['websites'] = []
for line in array:
Id = list(line.keys())[0]
length = len(line.get(Id))
time = line.get(Id)[length-1]
for x in range(0,length-1):
list1['websites'].append({'id':int(Id), 'url': line.get(Id)[x], 'time' : int(time)})
with open('urllist.txt', 'w') as outfile:
json.dump(list1,outfile)
@app.route('/')
@app.route('/index')
def index():
return render_template('index.html', urllist = urllist)
@app.route("/templateone")
def templateone():
return render_template('templateone.html', urllist = urllist)
@app.route("/templatetwo")
def templatetwo():
return render_template('templatetwo.html', urllist = urllist)
@app.route("/templatethree")
def templatethree():
return render_template('templatethree.html', urllist = urllist)
@app.route("/templatefour")
def templatefour():
return render_template('templatefour.html', urllist = urllist)
@app.route("/admin")
def admin():
refresh();
return render_template('admin.html', urllist = loaded_urllist, arrpos=arrpos)
@app.route('/recieve', methods=['POST'])
def recieve():
if request.method == 'POST':
names = request.get_json() #might have to make names (or array whatever) global so file can be rewritten outside
print(names, file=sys.stderr)
arrayToJson(names);
refresh();
return '', 200