-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
87 lines (62 loc) · 2.12 KB
/
script.py
File metadata and controls
87 lines (62 loc) · 2.12 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
86
87
import mysql.connector
import geocoder
from flask import Flask, request, render_template
app = Flask(__name__)
# home function to call homepage for user
@app.route("/")
def home():
return render_template('index.html')
@app.route("/about")
def about():
return render_template('about.html')
@app.route("/involve")
def involve():
return render_template('involve.html')
@app.route("/donate")
def donate():
return render_template('involve.html')
# guide function to call guidelines page for user
@app.route("/guide", methods=['GET', 'POST'])
def guide():
calamity = request.form['disaster']
fw = request.form['FW']
med = request.form['Med']
note = request.form['note']
g = geocoder.ip("me")
my_add = g.address
ADD = my_add
conn = mysql.connector.connect(host="localhost", user="root", password="root", port='3306', database="provider")
cursor = conn.cursor()
# Preparing SQL query to INSERT a record into the database.
insert_stmt = (
"INSERT INTO alert(Address, Calamity, FW, Med, Note)"
"VALUES (%s, %s, %s, %s, %s)"
)
data = (ADD, calamity, fw, med, note)
try:
# Executing the SQL command
cursor.execute(insert_stmt, data)
# Commit your changes in the database
conn.commit()
except:
# Rolling back in case of error
conn.rollback()
print("Data inserted")
# Closing the connection
conn.close()
return render_template('guide.html', Calamity=calamity, FW=fw, Med=med, Note=note)
# display function to call the display page for the responsible authorities
@app.route("/display", methods=['GET', 'POST'])
def display():
db = mysql.connector.connect(host="localhost", user="root", password="root", port='3306', database="provider")
my_cursor = db.cursor()
my_cursor.execute("Select * from alert")
reqres = my_cursor.fetchall()
my_cursor.execute("SELECT * FROM resources")
totres = my_cursor.fetchall()
avlres = 0
for i in totres:
if i[0] == reqres[0][0]:
avlres = i
return render_template('display.html', Res = reqres, Avl = avlres)
app.run(debug=True)