backup the project before clipgen starts
This commit is contained in:
parent
8025391655
commit
6a78b11a30
15
build_db.py
15
build_db.py
@ -27,7 +27,7 @@ cur.executemany(
|
|||||||
# import artist
|
# import artist
|
||||||
cur.executemany(
|
cur.executemany(
|
||||||
'insert into artist(id,name_rm,name) values(?, ?, ?)',
|
'insert into artist(id,name_rm,name) values(?, ?, ?)',
|
||||||
((row[0],row[1],row[2]) for row in data['Artist'][1:])
|
data['Artist'][1:]
|
||||||
)
|
)
|
||||||
|
|
||||||
# import credit
|
# import credit
|
||||||
@ -48,6 +48,12 @@ cur.executemany(
|
|||||||
data['Clip'][1:]
|
data['Clip'][1:]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# import song x album
|
||||||
|
cur.executemany(
|
||||||
|
"insert into song_album(song_id,album_id,track) values (?, ?, ?)",
|
||||||
|
(row[:3] for row in data['Song'][1:])
|
||||||
|
)
|
||||||
|
|
||||||
# import song x artist
|
# import song x artist
|
||||||
def creditparams(rows):
|
def creditparams(rows):
|
||||||
for row in rows[1:]:
|
for row in rows[1:]:
|
||||||
@ -56,13 +62,8 @@ def creditparams(rows):
|
|||||||
yield (row[0],artist,rows[0][index])
|
yield (row[0],artist,rows[0][index])
|
||||||
|
|
||||||
cur.executemany(
|
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 = ?))',
|
'insert or ignore into song_artist(song_id,artist_id,credit_id) values (?, (select id from artist where coalesce(nullif(name_rm,''),name) = ?), (select id from credit where name = ?))',
|
||||||
creditparams(data['Song'])
|
creditparams(data['Song'])
|
||||||
)
|
)
|
||||||
|
|
||||||
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()
|
db.commit()
|
||||||
39
db.sql
39
db.sql
@ -12,14 +12,6 @@ create table album(
|
|||||||
code char(3) 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(
|
create table artist(
|
||||||
id int primary key,
|
id int primary key,
|
||||||
name text not null,
|
name text not null,
|
||||||
@ -27,7 +19,7 @@ create table artist(
|
|||||||
);
|
);
|
||||||
|
|
||||||
create unique index ix_artist_name on artist(
|
create unique index ix_artist_name on artist(
|
||||||
coalesce(name_rm,name)
|
coalesce(nullif(name_rm,''),name)
|
||||||
);
|
);
|
||||||
|
|
||||||
create table credit(
|
create table credit(
|
||||||
@ -35,17 +27,6 @@ create table credit(
|
|||||||
name text not null
|
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(
|
create table motif(
|
||||||
id int primary key,
|
id int primary key,
|
||||||
name text not null
|
name text not null
|
||||||
@ -63,3 +44,21 @@ create index ix_motif on clip(
|
|||||||
motif_id
|
motif_id
|
||||||
);
|
);
|
||||||
|
|
||||||
|
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 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
|
||||||
|
);
|
||||||
@ -15,10 +15,12 @@ songplate = environment.get_template("songpage.jinja")
|
|||||||
|
|
||||||
db = sqlite3.connect("songbook.sqlite")
|
db = sqlite3.connect("songbook.sqlite")
|
||||||
|
|
||||||
|
|
||||||
for song in db.execute("SELECT name FROM song"):
|
for song in db.execute("SELECT name FROM song"):
|
||||||
filename = f"public/song/{song[0]}"
|
filename = f"public/song/{song[0]}"
|
||||||
content = songplate.render(
|
content = songplate.render(
|
||||||
songname=song[0],
|
songname=song[0],
|
||||||
|
clips=()
|
||||||
)
|
)
|
||||||
with open(filename, mode="w") as file:
|
with open(filename, mode="w") as file:
|
||||||
file.write(content)
|
file.write(content)
|
||||||
|
|||||||
BIN
reference.ods
BIN
reference.ods
Binary file not shown.
Loading…
Reference in New Issue
Block a user