eorzea-songbook/app.py

85 lines
1.4 KiB
Python

import flask
import sqlite3
app = flask.Flask('songbook')
@app.route('/song/<int:id>')
def songpage(id):
db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True)
# query song name
name, = db.execute('''
select
name
from
song
where
id = ?
''',
(id,)
).fetchone()
# query album info
album_info = db.execute('''
select
track, album.name, album.code
from
song_album
join
album
on
song_album.album_id=album.id
where
song_id = ?
''',
(id,)
).fetchall()
# query artist info
artist_info = db.execute('''
select
artist.name, artist.name_rm, credit.name
from
song_artist
join
artist
on
song_artist.artist_id=artist.id
join
credit
on
song_artist.credit_id=credit.id
where
song_id = ?
''',
(id,)
).fetchall()
# query clip info
clip_info = db.execute('''
select
song_id, motif_id, motif.name
from
clip
join
motif
on
clip.motif_id=motif.id
where
song_id = ?
''',
(id,)
).fetchall()
return flask.render_template('song.jinja',
name=name,
id=id,
album_info=album_info,
clip_info=clip_info,
artist_info=artist_info
)