homepage.veen.world/app/app.py

51 lines
1.6 KiB
Python
Raw Normal View History

2025-01-08 14:59:36 +01:00
import os
from flask import Flask, render_template
import requests
import hashlib
import yaml
from utils.configuration_resolver import ConfigurationResolver
2025-01-09 14:27:07 +01:00
from utils.cache_manager import CacheManager
2025-01-08 14:59:36 +01:00
2025-01-09 14:27:07 +01:00
# Initialize the CacheManager
cache_manager = CacheManager()
2025-01-09 14:27:07 +01:00
# Clear cache on startup
cache_manager.clear_cache()
2025-01-08 14:59:36 +01:00
def load_config(app):
"""Load and resolve the configuration."""
# Lade die Konfigurationsdatei
with open("config.yaml", "r") as f:
config = yaml.safe_load(f)
# Resolve links in the configuration
resolver = ConfigurationResolver(config)
resolver.resolve_links()
# Update the app configuration
app.config.update(resolver.get_config())
2025-01-08 14:59:36 +01:00
app = Flask(__name__)
load_config(app)
2025-01-08 14:59:36 +01:00
# Hole die Umgebungsvariable FLASK_ENV oder setze einen Standardwert
FLASK_ENV = os.getenv("FLASK_ENV", "production")
2025-01-08 14:59:36 +01:00
@app.before_request
def reload_config_in_dev():
2025-01-09 12:20:57 +01:00
if FLASK_ENV == "development":
load_config(app)
2025-01-09 14:27:07 +01:00
# Cache the icons
for card in app.config["cards"]:
2025-01-09 14:27:07 +01:00
card["icon"]["cache"] = cache_manager.cache_file(card["icon"]["source"])
2025-01-09 14:27:07 +01:00
app.config["company"]["logo"]["cache"] = cache_manager.cache_file(app.config["company"]["logo"]["source"])
app.config["company"]["favicon"]["cache"] = cache_manager.cache_file(app.config["company"]["favicon"]["source"])
2025-01-08 14:59:36 +01:00
@app.route('/')
def index():
return render_template("pages/index.html.j2", cards=app.config["cards"], company=app.config["company"], navigation=app.config["navigation"])
2025-01-08 14:59:36 +01:00
if __name__ == "__main__":
app.run(debug=(FLASK_ENV == "development"), host="0.0.0.0", port=5000)