Files
kolibrios.org/app.py
T

83 lines
1.6 KiB
Python
Raw Normal View History

2025-05-24 11:41:35 +03:00
from os import path, listdir
2025-03-22 18:27:43 +03:00
from datetime import date
from configparser import ConfigParser
2025-05-24 11:41:35 +03:00
from flask import (
Flask,
abort,
redirect,
render_template,
request,
send_from_directory,
url_for,
)
cp = ConfigParser()
2025-03-22 18:27:43 +03:00
app = Flask(__name__)
def load_all_locales():
locales = {}
2025-05-24 11:41:35 +03:00
locales_dir = "locales"
for filename in listdir(locales_dir):
if filename.endswith(".ini"):
lang = path.splitext(filename)[0]
cp = ConfigParser()
2025-05-24 11:41:35 +03:00
with open(path.join(locales_dir, filename), encoding="utf-8") as f:
cp.read_file(f)
locales[lang] = {section: dict(cp[section]) for section in cp.sections()}
2025-05-24 11:41:35 +03:00
return locales
2025-05-24 11:41:35 +03:00
locales = load_all_locales()
2025-03-22 18:27:43 +03:00
2025-05-24 11:41:35 +03:00
@app.route("/favicon.ico")
def favicon():
return send_from_directory(
app.static_folder,
"favicon.ico",
mimetype="image/vnd.microsoft.icon"
)
2025-03-24 09:02:58 +02:00
@app.route("/")
def home():
return redirect(url_for("index", lang="en"))
2025-05-24 11:41:35 +03:00
2025-03-22 18:27:43 +03:00
@app.route("/<lang>")
def index(lang):
2025-05-24 11:41:35 +03:00
if lang not in locales:
abort(404)
return render_template(
f"{lang}.html",
locale=locales[lang],
lang=lang,
year=date.today().year,
current=request.endpoint,
)
2025-03-22 18:27:43 +03:00
@app.route("/<lang>/download")
def download_page(lang):
2025-05-24 11:41:35 +03:00
if lang not in locales:
abort(404)
return render_template(
"tmpl/download.htm",
locale=locales[lang],
lang=lang,
year=date.today().year,
current=request.endpoint,
)
2025-03-22 18:27:43 +03:00
2025-03-24 09:02:58 +02:00
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True)