diff --git a/app.py b/app.py index 5433fc3..bbdc625 100644 --- a/app.py +++ b/app.py @@ -3,6 +3,100 @@ 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): @@ -25,7 +119,7 @@ def songpage(id): album_info = db.execute(''' select - track, album.name, album.code + album_id, track, album.name, album.code from song_album join @@ -34,6 +128,8 @@ def songpage(id): song_album.album_id=album.id where song_id = ? + order by + album_id ''', (id,) ).fetchall() @@ -55,6 +151,9 @@ def songpage(id): song_artist.credit_id=credit.id where song_id = ? + order by + credit_id, + artist.name_rm ''', (id,) ).fetchall() @@ -72,6 +171,8 @@ def songpage(id): clip.motif_id=motif.id where song_id = ? + order by + song_id ''', (id,) ).fetchall() diff --git a/build_db.py b/build_db.py index a95db16..517b43d 100644 --- a/build_db.py +++ b/build_db.py @@ -10,8 +10,8 @@ cur = db.cursor() with open('db.sql') as file: db.executescript(file.read()) -data = pyexcel_odsr.get_data('reference.ods') -clipdata = pyexcel_odsr.get_data('reference_clips.ods') +data = pyexcel_odsr.get_data('reference.ods', skip_empty_rows=True) +clipdata = pyexcel_odsr.get_data('reference_clips.ods', skip_empty_rows=True) # import song cur.executemany( @@ -37,18 +37,16 @@ cur.executemany( data['Credit'][1:] ) -print(clipdata['Motif'][1:]) - # import motif cur.executemany( - 'insert into motif(id,name) values(?, ?)', - clipdata['Motif'][1:] + 'insert into motif(id,name,type) values(?, ?, ?)', + ((row[0],row[1],'' if len(row)<3 else row[2]) for row in clipdata['Motif'][1:]) ) # import clip cur.executemany( - 'insert into clip(start_ms,duration_ms,song_id,motif_id) values (?, ?, ?, ?)', - clipdata['Clip'][1:] + 'insert into clip(start_ms,duration_ms,song_id,motif_id,feature) values (?, ?, ?, ?, ?)', + ((row[0],row[1],row[2],row[3],0 if len(row)<5 else row[4]) for row in clipdata['Clip'][1:]) ) # import song x album diff --git a/db.sql b/db.sql index 7e15673..f636c68 100644 --- a/db.sql +++ b/db.sql @@ -31,7 +31,8 @@ create table credit( create table motif( id int primary key, - name text not null + name text not null, + type int not null ); create table clip( @@ -39,6 +40,7 @@ create table clip( motif_id int not null references motif(id), start_ms int not null, duration_ms int not null, + feature int not null, primary key(song_id,motif_id) ); diff --git a/reference.ods b/reference.ods index 3bee5a0..d3a7883 100644 Binary files a/reference.ods and b/reference.ods differ diff --git a/reference_clips.ods b/reference_clips.ods index 7ff38b8..0b3983c 100644 Binary files a/reference_clips.ods and b/reference_clips.ods differ diff --git a/templates/album.jinja b/templates/album.jinja new file mode 100644 index 0000000..a25df5a --- /dev/null +++ b/templates/album.jinja @@ -0,0 +1,16 @@ +{% extends "base.jinja" %} +{% block title %}{{ album_info[0] }}{% endblock %} + +{% block content %} + +

{{ album_info[0] }}

+

Released: {{ album_info[1] }} + + +

+ +{% endblock %} \ No newline at end of file diff --git a/templates/motif.jinja b/templates/motif.jinja new file mode 100644 index 0000000..8f67cbe --- /dev/null +++ b/templates/motif.jinja @@ -0,0 +1,22 @@ +{% extends "base.jinja" %} + +{% block title %}{{ name }}{% endblock %} + +{% block content %} +

Motif: {{ name }}

+ + + +

Clips:

+
    +{% for song_id, motif_id, song in clip_info %} +
  • + + {{ song }} +
  • +{% endfor %} + +{% endblock %} \ No newline at end of file diff --git a/templates/song.jinja b/templates/song.jinja index 6e65366..0a88605 100644 --- a/templates/song.jinja +++ b/templates/song.jinja @@ -2,7 +2,7 @@ {% block title %}{{ name }}{% endblock %} {% block content %} -

    Now Playing: {{ id }}. {{ name }} ({% for _, _, album_code in album_info %}{{ album_code }}{% if not loop.last %}, {% endif %}{% endfor %}) +

    Now Playing: {{ id }}. {{ name }} ({% for _, _, _, album_code in album_info %}{{ album_code }}{% if not loop.last %}, {% endif %}{% endfor %})

    @@ -18,11 +18,13 @@

    Album:

      -{% for track, album_name, album_code in album_info %} -
    • {{ album_name }} #{{ track }}
    • +{% for id, track, album_name, album_code in album_info %} +
    • {{ album_name }} #{{ track }}
    • {% endfor %}
    + +

    Clips:

      {% for song_id, motif_id, motif in clip_info %} @@ -30,7 +32,8 @@ {{ motif }} + + {{ motif }} {% endfor %}