backup the project before clipgen starts

This commit is contained in:
Effie 2023-06-03 13:45:33 +10:00
parent 8025391655
commit 6a78b11a30
4 changed files with 29 additions and 27 deletions

View File

@ -27,7 +27,7 @@ cur.executemany(
# import artist
cur.executemany(
'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
@ -48,6 +48,12 @@ cur.executemany(
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
def creditparams(rows):
for row in rows[1:]:
@ -56,13 +62,8 @@ def creditparams(rows):
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 = ?))',
'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'])
)
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()

39
db.sql
View File

@ -12,14 +12,6 @@ create table album(
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,
@ -27,7 +19,7 @@ create table artist(
);
create unique index ix_artist_name on artist(
coalesce(name_rm,name)
coalesce(nullif(name_rm,''),name)
);
create table credit(
@ -35,17 +27,6 @@ create table credit(
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
@ -63,3 +44,21 @@ create index ix_motif on clip(
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
);

View File

@ -15,10 +15,12 @@ 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],
clips=()
)
with open(filename, mode="w") as file:
file.write(content)

Binary file not shown.