fix: serve dashboard.html directly from current directory instead of static folder
Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@ -5,11 +5,11 @@ Provides a simple API endpoint that aggregates weather and ABS data for the dash
|
||||
This avoids CORS issues with the ABS API.
|
||||
|
||||
Run with: python3 dashboard_api.py
|
||||
Access: http://localhost:5000/api/dashboard
|
||||
Access: http://localhost:5000/
|
||||
"""
|
||||
|
||||
import requests
|
||||
from flask import Flask, jsonify
|
||||
from flask import Flask, jsonify, Response
|
||||
import os
|
||||
|
||||
app = Flask(__name__)
|
||||
@ -70,12 +70,12 @@ def fetch_weather():
|
||||
response = requests.get(WEATHER_URL, timeout=10)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
|
||||
|
||||
if "current_weather" in data:
|
||||
weather = data["current_weather"]
|
||||
code = weather["weathercode"]
|
||||
weather_info = WEATHER_CODES.get(code, {"icon": "🌐", "text": "Unbekannt"})
|
||||
|
||||
|
||||
return {
|
||||
"temperature": round(weather["temperature"], 1),
|
||||
"windspeed": round(weather["windspeed"], 1),
|
||||
@ -96,12 +96,12 @@ def fetch_abs_data():
|
||||
"Authorization": f"Bearer {ABS_TOKEN}",
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
|
||||
# Get user data with progress
|
||||
response = requests.get(f"{ABS_BASE_URL}/api/me", headers=headers, timeout=10)
|
||||
response.raise_for_status()
|
||||
user_data = response.json()
|
||||
|
||||
|
||||
if "mediaProgress" in user_data and user_data["mediaProgress"]:
|
||||
# Sort by lastUpdate, get latest
|
||||
sorted_progress = sorted(
|
||||
@ -111,7 +111,7 @@ def fetch_abs_data():
|
||||
)
|
||||
latest = sorted_progress[0]
|
||||
library_item_id = latest.get("libraryItemId")
|
||||
|
||||
|
||||
# Get item details
|
||||
item_response = requests.get(
|
||||
f"{ABS_BASE_URL}/api/items/{library_item_id}",
|
||||
@ -120,12 +120,12 @@ def fetch_abs_data():
|
||||
)
|
||||
item_response.raise_for_status()
|
||||
item_data = item_response.json()
|
||||
|
||||
|
||||
metadata = item_data.get("media", {}).get("metadata", {})
|
||||
title = metadata.get("title", "Unbekannt")
|
||||
author = metadata.get("author", "")
|
||||
media_type = item_data.get("mediaType", "item")
|
||||
|
||||
|
||||
return {
|
||||
"title": title,
|
||||
"author": author,
|
||||
@ -134,7 +134,7 @@ def fetch_abs_data():
|
||||
"currentTime": format_duration(latest.get("currentTime", 0)),
|
||||
"duration": format_duration(latest.get("duration", 0)),
|
||||
}
|
||||
|
||||
|
||||
return None
|
||||
except Exception as e:
|
||||
print(f"ABS API error: {e}")
|
||||
@ -146,7 +146,7 @@ def get_dashboard_data():
|
||||
"""Return combined dashboard data"""
|
||||
weather = fetch_weather()
|
||||
abs_data = fetch_abs_data()
|
||||
|
||||
|
||||
return jsonify({
|
||||
"weather": weather,
|
||||
"audiobook": abs_data,
|
||||
@ -155,8 +155,12 @@ def get_dashboard_data():
|
||||
|
||||
@app.route("/")
|
||||
def serve_dashboard():
|
||||
"""Serve the dashboard HTML"""
|
||||
return app.send_static_file("dashboard.html")
|
||||
"""Serve the dashboard HTML directly from the current directory"""
|
||||
try:
|
||||
with open("dashboard.html", "r", encoding="utf-8") as f:
|
||||
return Response(f.read(), mimetype="text/html")
|
||||
except FileNotFoundError:
|
||||
return "Error: dashboard.html not found. Please run from the project directory.", 404
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@ -164,5 +168,7 @@ if __name__ == "__main__":
|
||||
if not os.path.exists("dashboard.html"):
|
||||
print("Error: dashboard.html not found. Please run from the project directory.")
|
||||
exit(1)
|
||||
|
||||
|
||||
print("Starting dashboard server...")
|
||||
print("Open http://localhost:5000 in your browser")
|
||||
app.run(host="0.0.0.0", port=5000, debug=False)
|
||||
|
||||
Reference in New Issue
Block a user