-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
70 lines (40 loc) · 1.19 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
from flask import Flask, render_template, jsonify,request
from flask_mysqldb import MySQL
from camera import Camera
from flask_cors import CORS
from twilo_messaging import send_sms
app = Flask(__name__)
CORS(app)
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = ''
app.config['MYSQL_DB'] = 'securitycameraappdb'
mysql = MySQL(app)
camera = Camera()
@app.route("/")
def home():
cur = mysql.connection.cursor()
cur.execute("SELECT * FROM users")
fetch_data = cur.fetchall()
cur.close()
return render_template("home.html", data = fetch_data)
@app.route("/start")
def start():
camera.start()
return jsonify(message = "camera started"), 200
@app.route("/stop")
def stop():
camera.stop()
return jsonify(message = "camera stopped"), 200
@app.route("/motion-detected",methods=["POST"])
def motion_detected():
data = request.get_json()
print(data)
if 'url' in data:
print("URL:", data['url'])
send_sms.send_notification(data['url'])
else:
print("url not in incoming data")
return jsonify({}), 201
if __name__ == "__main__":
app.run(debug=True)