-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase-init.py
44 lines (38 loc) · 1.18 KB
/
database-init.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# take raw text generated by the Keynote parser and put data into the database
import sqlite3
with open("out.txt") as file:
songs = []
title = ''
lyrics = ''
state = 'none'
first = True
for line in file:
s = line.strip()
if s == '#Title':
if (not first):
songs.append([title, lyrics])
else:
first = False
title = ''
lyrics = ''
state = 'title'
elif s == '#Page':
if state == 'lyrics':
lyrics += '\n'
state = 'lyrics'
else:
if state == 'title':
title = s
elif state == 'lyrics':
lyrics += s + '\n'
con = sqlite3.connect("songs.sqlite3")
cur = con.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS song(id integer primary key autoincrement, title, lyrics)")
for song in songs:
cur.execute("INSERT INTO song VALUES(NULL, ?, ?)", (song[0], song[1]))
con.commit()
# songs = cur.execute("SELECT * FROM song").fetchall()
# for song in songs:
# print('Title : ' + song[1])
# print('Lyrics: ' + song[2])
con.close()