-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.py
30 lines (24 loc) · 797 Bytes
/
web.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
from flask import Flask, render_template, jsonify
import json
import os
app = Flask(__name__)
# Path to the tag states JSON file
STATE_FILE = "tag_states.json"
def load_tag_states():
"""Load the current tag states from the JSON file."""
if os.path.exists(STATE_FILE):
with open(STATE_FILE, "r") as f:
return json.load(f)
return {}
@app.route('/')
def index():
"""Main page to display the state of the tags."""
tag_states = load_tag_states()
return render_template("index.html", tag_states=tag_states)
@app.route('/api/tags')
def get_tags():
"""API endpoint to get the current tag states as JSON."""
tag_states = load_tag_states()
return jsonify(tag_states)
if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0', port=5000)