remove the 'main' sheet
This commit is contained in:
commit
6585844e03
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
songbook.sqlite
|
||||
public/
|
||||
73
build_db.py
Normal file
73
build_db.py
Normal file
@ -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()
|
||||
65
db.sql
Normal file
65
db.sql
Normal file
@ -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
|
||||
);
|
||||
|
||||
33
generate.py
Normal file
33
generate.py
Normal file
@ -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]
|
||||
# )
|
||||
# )
|
||||
BIN
reference.ods
Normal file
BIN
reference.ods
Normal file
Binary file not shown.
13
templates/songpage.jinja
Normal file
13
templates/songpage.jinja
Normal file
@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>title</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<script src="script.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Now Playing: {{ songname }}</h1>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in New Issue
Block a user