-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
113 lines (96 loc) · 3.99 KB
/
app.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
104
105
106
107
108
109
110
111
112
113
from flask import Flask, render_template, request, redirect
import json
import pyrebase
app = Flask(__name__)
with open('api_key/config.json') as file:
config = json.loads(file.read())
firebase = pyrebase.initialize_app(config)
db = firebase.database()
storage = firebase.storage()
@app.route('/')
def index():
data = db.get()
data_dict = {}
data_list = []
for key, value in data.val().items():
data_dict['Name'] = value['Name']
data_dict['user_id'] = key
for com_key, com_value in value['Complaints'].items():
data_dict['lat'] = com_value['lat']
data_dict['long'] = com_value['long']
data_dict['description'] = com_value['description']
data_dict['complaint_id'] = com_key
data_dict['status'] = com_value['status']
data_dict['reason'] = com_value['reason']
# print(com_value['description'])
path = 'photos/' + key + com_key + '.jpg'
data_dict['image_url'] = storage.child(path).get_url(config).split("&token=")[0]
# print(data_dict)
data_list.append(data_dict.copy())
print(data_list)
return render_template('index.html', data = data_list)
@app.route('/user')
def user():
data = db.get()
data_dict = {}
data_list = []
for key, value in data.val().items():
data_dict['Name'] = value['Name']
for com_key, com_value in value['Complaints'].items():
data_dict['lat'] = com_value['lat']
data_dict['long'] = com_value['long']
data_dict['description'] = com_value['description']
data_dict['status'] = com_value['status']
data_dict['reason'] = com_value['reason']
path = 'photos/' + key + com_key + '.jpg'
data_dict['image_url'] = storage.child(path).get_url(config).split("&token=")[0]
data_list.append(data_dict.copy())
return render_template('user.html', data = data_list)
@app.route('/panel')
def panel():
data = db.get()
data_dict = {}
data_list = []
for key, value in data.val().items():
data_dict['Name'] = value['Name']
for com_key, com_value in value['Complaints'].items():
data_dict['lat'] = com_value['lat']
data_dict['long'] = com_value['long']
data_dict['description'] = com_value['description']
path = 'photos/' + key + com_key + '.jpg'
data_dict['image_url'] = storage.child(path).get_url(config).split("&token=")[0]
data_list.append(data_dict.copy())
print(data_list)
return render_template('panel.html', data = data_list)
@app.route('/locations')
def locations():
data = db.get()
data_dict = {}
data_list = []
for key, value in data.val().items():
data_dict['Name'] = value['Name']
for com_key, com_value in value['Complaints'].items():
data_dict['lat'] = com_value['lat']
data_dict['long'] = com_value['long']
data_dict['description'] = com_value['description']
path = 'photos/' + key + com_key + '.jpg'
data_dict['image_url'] = storage.child(path).get_url(config).split("&token=")[0]
data_list.append(data_dict.copy())
print(data_list)
return render_template('locations.html', data = data_list)
@app.route('/del_complaint', methods=['POST'])
def del_complaint():
reason = request.form.get('reason')
user_id = request.form.get('user_id')
complaint_id = request.form.get('complaint_id')
db.child(user_id).child("Complaints").child(complaint_id).child('status').set('false')
db.child(user_id).child("Complaints").child(complaint_id).child('reason').set(reason)
return redirect('/')
@app.route('/approve', methods=['POST'])
def approve():
user_id = request.form.get('user_id')
complaint_id = request.form.get('complaint_id')
db.child(user_id).child("Complaints").child(complaint_id).child('status').set('true')
return redirect('/')
if __name__ == '__main__':
app.run(debug=True)