-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
59 lines (44 loc) · 1.26 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
from flask import Flask, render_template, request, jsonify
import json
app = Flask(__name__)
# Path to the JSON file
json_file = 'config.json'
def load_json():
with open(json_file, 'r') as file:
return json.load(file)
def save_json(data):
with open(json_file, 'w') as file:
json.dump(data, file, indent=4)
@app.route('/')
def index():
json_data = load_json()
return render_template('index.html', json_data=json_data)
@app.route('/json', methods=['GET'])
def get_json():
json_data = load_json()
return jsonify(json_data)
@app.route('/json', methods=['POST'])
def edit_json():
new_data = request.get_json()
json_data = load_json()
json_data.update(new_data)
save_json(json_data)
return jsonify(json_data)
@app.route('/status', methods=['GET'])
def get_status():
json_data = load_json()
status = check_config_status(json_data)
return jsonify({'status': status})
import cv2
def check_config_status(json_data):
try:
cap = cv2.VideoCapture(json_data["rtsp_video"])
ret, frame = cap.read()
if ret:
return 'Working'
return 'Not Working'
except Exception as e:
print(e)
return 'Not Working'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)