commit 6585844e03f7102ee63eaf4c36bdf5654fe041ce Author: Effie Date: Tue May 23 11:58:46 2023 +1000 remove the 'main' sheet diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bb70d96 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +songbook.sqlite +public/ \ No newline at end of file diff --git a/build_db.py b/build_db.py new file mode 100644 index 0000000..c78e0da --- /dev/null +++ b/build_db.py @@ -0,0 +1,73 @@ +import sqlite3 +import os +import pyexcel_odsr + +os.remove('songbook.sqlite') +db = sqlite3.connect("songbook.sqlite") + +cur = db.cursor() + +with open('db.sql') as file: + db.executescript(file.read()) + +data = pyexcel_odsr.get_data('reference.ods') + +def nullifempty(cell): + return None if len(cell)==0 else cell + +# import song +cur.executemany( + 'insert or ignore into song(id,name,name_jp) values(?, ?, ?)', + ((row[0],row[3],None if len(row)<5 else nullifempty(row[4])) for row in data['Song'][1:]) +) + +# import album +cur.executemany( + 'insert into album(id,name,date,code) values (?, ?, ?, ?)', + data['Album'][1:] +) + +# import artist +cur.executemany( + 'insert into artist(id,name_rm,name) values(?, ?, ?)', + ((row[0],nullifempty(row[1]),row[2]) for row in data['Artist'][1:]) +) + +# import credit +cur.executemany( + 'insert into credit(id,name) values(?, ?)', + data['Credit'][1:] +) + +# import motif +cur.executemany( + 'insert into motif(id,name) values(?, ?)', + data['Motif'][1:] +) + +# import clip +cur.executemany( + 'insert into clip(start_ms,duration_ms,song_id,motif_id) values (?, ?, ?, ?)', + data['Clip'][1:] +) + +# import song x artist +def creditparams(rows): + for row in rows[1:]: + for index,artist in enumerate(row[5:], 5): + if len(artist)>0: + yield (row[0],artist,rows[0][index]) + +cur.executemany( + 'insert or ignore into song_artist(song_id,artist_id,credit_id) values (?, (select id from artist where coalesce(name_rm,name) = ?), (select id from credit where name = ?))', + creditparams(data['Song']) +) + +# import song x album +# "insert into song_album(album_id,track,song_id) values (?, ?, (select id from song where name = ? and coalesce(name_jp,'') = coalesce(?,'')))" +cur.executemany( + "insert into song_album(song_id,album_id,track) values (?, ?, ?)", + ((row[0],row[1],row[2]) for row in data['Song'][1:]) +) + +db.commit() \ No newline at end of file diff --git a/db.sql b/db.sql new file mode 100644 index 0000000..b4de453 --- /dev/null +++ b/db.sql @@ -0,0 +1,65 @@ +create table song( + id int primary key, + name text not null, + name_jp text, + unique(name,name_jp) +); + +create table album( + id int primary key, + name text not null, + date date not null, + code char(3) not null +); + +create table song_album( + song_id int not null references song(id), + album_id int not null references album(id), + track int not null, + primary key(album_id,track), + unique(song_id,album_id) +); + +create table artist( + id int primary key, + name text not null, + name_rm text +); + +create unique index ix_artist_name on artist( + coalesce(name_rm,name) +); + +create table credit( + id int primary key, + name text not null +); + +create table song_artist( + song_id int not null references song(id), + artist_id int not null references artist(id), + credit_id int not null references credit(id), + primary key(song_id,artist_id,credit_id) +); + +create index ix_song_artist on song_artist( + artist_id +); + +create table motif( + id int primary key, + name text not null +); + +create table clip( + song_id int not null references song(id), + motif_id int not null references motif(id), + start_ms int not null, + duration_ms int not null, + primary key(song_id,motif_id) +); + +create index ix_motif on clip( + motif_id +); + diff --git a/generate.py b/generate.py new file mode 100644 index 0000000..532dfe6 --- /dev/null +++ b/generate.py @@ -0,0 +1,33 @@ +import sqlite3 +import jinja2 +import os + +for dirname in [ + "public/song", + "public/motif", + "public/album", + "public/clip", +]: + os.makedirs(dirname, exist_ok=True) + +environment = jinja2.Environment(loader=jinja2.FileSystemLoader("templates/")) +songplate = environment.get_template("songpage.jinja") + +db = sqlite3.connect("songbook.sqlite") + +for song in db.execute("SELECT name FROM song"): + filename = f"public/song/{song[0]}" + content = songplate.render( + songname=song[0], + ) + 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] +# ) +# ) \ No newline at end of file diff --git a/reference.ods b/reference.ods new file mode 100644 index 0000000..ec82d51 Binary files /dev/null and b/reference.ods differ diff --git a/templates/songpage.jinja b/templates/songpage.jinja new file mode 100644 index 0000000..55f3a42 --- /dev/null +++ b/templates/songpage.jinja @@ -0,0 +1,13 @@ + + + + title + + + + + +

Now Playing: {{ songname }}

+ + +