-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.py
More file actions
43 lines (36 loc) · 1009 Bytes
/
dashboard.py
File metadata and controls
43 lines (36 loc) · 1009 Bytes
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
#!/usr/bin/env python3
from flask import Flask, render_template
import json
import os
app = Flask(__name__)
FEED_FILE = "data/feed_normalized.json"
# -------------------------
# Load feed
# -------------------------
def load_feed():
if os.path.exists(FEED_FILE):
with open(FEED_FILE, "r", encoding="utf-8") as f:
return json.load(f)
return []
# -------------------------
# Group feed by category
# -------------------------
def group_by_category(feed):
categories = {}
for item in feed:
cat = item.get("category", "uncategorized")
categories.setdefault(cat, []).append(item)
return categories
# -------------------------
# Routes
# -------------------------
@app.route("/")
def index():
feed = load_feed()
grouped = group_by_category(feed)
return render_template("index.html", grouped=grouped)
# -------------------------
# Run
# -------------------------
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5052, debug=True)