import flask import sqlite3 app = flask.Flask('songbook') # BLANK PAGE # @app.route('/album/') # def page(id): # db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True) # return flask.render_template('motif.jinja', # ) # ALBUM PAGES @app.route('/album/') def albumpage(id): db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True) album_info = db.execute(''' select name, date from album where id = ? ''', (id,) ).fetchone() song_info = db.execute(''' select song_id, track, song.name, song.name_jp from song_album join song on song_album.song_id=song.id where album_id = ? ''', (id,) ).fetchall() return flask.render_template('album.jinja', album_info=album_info, song_info=song_info ) # MOTIF PAGES @app.route('/motif/') def motifpage(id): db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True) # query motif name, = db.execute(''' select name from motif where id = ? ''', (id,) ).fetchone() # query clips clip_info = db.execute(''' select song_id, motif_id, song.name from clip join song on clip.song_id=song.id where motif_id = ? order by song_id ''', (id,) ).fetchall() return flask.render_template('motif.jinja', name=name, clip_info=clip_info ) # SONG PAGES @app.route('/song/') 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 album_id, track, album.name, album.code from song_album join album on song_album.album_id=album.id where song_id = ? order by album_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 = ? order by credit_id, artist.name_rm ''', (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 = ? order by 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 )