-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
103 lines (85 loc) · 2.49 KB
/
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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from flask import Flask, url_for, render_template, request, redirect, url_for, jsonify
import json
from pprint import pprint
import requests
bad_words = []
bd_count = 0
class Badword:
def __init__(self, nome, id):
self.id = id
self.badword = nome
def to_dict(self):
return self.__dict__
def load_badwords():
with open('badwords.json') as f:
data = json.load(f)
for d in data['badwords']:
b = Badword(d['badword'], d['id'])
bad_words.append(b)
# print(json.dumps(bad_words[0].__dict__))
def save_file(d):
with open('badwords.json', 'w') as outfile:
outfile.write('{\n "badwords":')
json.dump(d, outfile, indent=4)
outfile.write('\n}')
load_badwords()
app = Flask(__name__)
@app.route('/', methods=['POST', 'GET'])
def index(bad_words = None):
return render_template('index.html')
@app.route('/submit_badword', methods=['POST', 'GET'])
def submit_badword():
bid = int(bad_words[-1].id) + 1
bid = str(bid).encode("utf-8").decode("utf-8")
badword = request.form['text']
b = Badword(badword, bid)
bad_words.append(b)
d = []
for b in bad_words:
d.append(b.__dict__)
return jsonify({'badwords': d})
@app.route('/admin')
def admin(bad_words = bad_words):
print(bad_words)
return render_template('admin.html', bad_words=bad_words)
@app.route('/admin', methods = ["POST"])
def addOne():
bid = int(bad_words[-1].id) + 1
bid = str(bid).encode("utf-8").decode("utf-8")
badword = request.form['text']
b = Badword(badword, bid)
bad_words.append(b)
d = []
for b in bad_words:
d.append(b.__dict__)
save_file(d)
return jsonify({'badwords': d})
@app.route('/delete/<int:id>', methods=['POST'])
def remove(id):
id = int(id)
for i in bad_words:
# print(i.id)
# print(type(int(i.id)))
# print(id)
# print('ayee')
if int(i.id) == id:
# print('achou!')
# print(i.nome)
bad_words.remove(i)
d = []
for b in bad_words:
d.append(b.__dict__)
save_file(d)
return jsonify({'badwords': d})
@app.route('/badwords', methods = ["GET"])
def returnAll():
d = []
for b in bad_words:
d.append(b.__dict__)
return jsonify({'badwords': d})
@app.route('/badwords/<string:id>', methods=['GET'])
def returnOne(id):
id = int(id)
return jsonify({'badword' : bad_words[id].__dict__})
if __name__ == '__main__':
app.run(debug=True)