Rework my page and add info from listenbrainz
This commit is contained in:
@@ -1,7 +1,19 @@
|
||||
import os
|
||||
import magic
|
||||
from pathlib import Path
|
||||
from htmlmin import minify
|
||||
from flask import Blueprint, render_template, send_from_directory, send_file, abort
|
||||
from datetime import datetime, timedelta
|
||||
from musicbrainzngs import get_image_front
|
||||
from flask import (
|
||||
Blueprint,
|
||||
render_template,
|
||||
send_file,
|
||||
send_from_directory,
|
||||
make_response,
|
||||
abort,
|
||||
)
|
||||
|
||||
from .modules.api.lb import listens, listening
|
||||
|
||||
bp = Blueprint(
|
||||
"risdeveau",
|
||||
@@ -11,10 +23,10 @@ bp = Blueprint(
|
||||
static_folder=None
|
||||
)
|
||||
|
||||
def render_tmpl(filename: str) -> str:
|
||||
def render_tmpl(filename: str, **kwargs) -> str:
|
||||
template_path = os.path.join("risdeveau/templates", filename)
|
||||
return minify(
|
||||
render_template(template_path),
|
||||
render_template(template_path, **kwargs),
|
||||
remove_empty_space=True
|
||||
)
|
||||
|
||||
@@ -26,14 +38,15 @@ def static(filename: str):
|
||||
return send_file(path)
|
||||
return abort(404)
|
||||
|
||||
@bp.route("/asset/mb/<mbid>")
|
||||
def mb_cover(mbid):
|
||||
r = make_response(image := get_image_front(mbid, "250"))
|
||||
r.headers['Content-Type'] = magic.from_buffer(image[:2048], mime=True)
|
||||
r.headers['Cache-Control'] = 'public, max-age=86400'
|
||||
r.headers['Expires'] = (datetime.now() + timedelta(days=1)) \
|
||||
.strftime('%a, %d %b %Y %H:%M:%S GMT')
|
||||
return r
|
||||
|
||||
@bp.route("/")
|
||||
def index():
|
||||
return render_tmpl('index.html')
|
||||
|
||||
@bp.route("/contacts")
|
||||
def contacts():
|
||||
return render_tmpl('contacts.html')
|
||||
|
||||
@bp.route("/donate")
|
||||
def donate():
|
||||
return render_tmpl('donate.html')
|
||||
return render_tmpl('index.html', lb=listens, lb_now=listening)
|
||||
|
||||
Reference in New Issue
Block a user