queries album info and puts it in jinja expressions

This commit is contained in:
Effie 2023-06-04 15:22:16 +10:00
parent fddc6a9823
commit 6880b57844
3 changed files with 46 additions and 16 deletions

View File

@ -1,11 +1,12 @@
import sqlite3
import jinja2
import os
import shutil
for dirname in [
"public/song",
"public/motif",
"public/album",
"public/album"
]:
os.makedirs(dirname, exist_ok=True)
@ -14,21 +15,40 @@ songplate = environment.get_template("songpage.jinja")
db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True)
# generate song pages
for song in db.execute("SELECT name FROM song"):
filename = f"public/song/{song[0]}"
for id, name, name_jp in db.execute('''
select
id, name, name_jp
from
song
'''):
# query album info
album_info = db.execute('''
select
album_id, track, album.name, album.code
from
song_album
join
album
on
song_album.album_id=album.id
where
song_id = ?
''',
(id,)
).fetchall()
print(album_info)
filename = f"public/song/{id:04}"
content = songplate.render(
songname=song[0],
clips=()
name=name,
id=id,
album_info=album_info
)
with open(filename, mode="w") as file:
file.write(content)
print(f"... wrote {filename}")
# template = environment.from_string("Now Playing: {{ song }}")
# for songname in songnames:
# print(
# template.render(
# song=songname[0]
# )
# )
print(f"... wrote {filename}")

2
deploy.sh Executable file
View File

@ -0,0 +1,2 @@
sudo rm -r /var/www/eorzea-songbook
sudo cp -r public/ /var/www/eorzea-songbook

View File

@ -7,7 +7,15 @@
</head>
<body>
<h1>Now Playing: {{ songname }}</h1>
<h1>Now Playing: {{ id }}. {{ name }} ({% for _, _, _, album_code in album_info %}{{ album_code }}{% if not loop.last %}, {% endif %}{% endfor %})
</h1>
<p>Artist: </p>
<p>Album: </p>
<ul>
{% for album_id, track, album_name, album_code in album_info %}
<li>{{ album_name }} #{{ track }}</li>
{% endfor %}
</ul>
<p>Clips: </p>
</body>
</html>