-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase_transfer.py
100 lines (82 loc) · 3.08 KB
/
database_transfer.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import sqlite3
from sqlite3 import Error
import openpyxl, os
def create_connection(db_file):
""" create a database connection to a SQLite database """
try:
conn = sqlite3.connect("playlist.sqlite3") #??????????
cur = conn.cursor()
print(sqlite3.version)
return conn
except Error as e:
print(e)
# finally:
# conn.close()
def create_table(conn):
try:
# conn.execute("""CREATE TABLE IF NOT EXISTS playlist(
# song_id INTEGER PRIMARY KEY,
# song_name TEXT,
# metal_instrumental INTEGER,
# megasync_bool INTEGER,
# memorycard_bool INTEGER,
# youtube_bool INTEGER default 0)"""
# )
# conn.execute("""CREATE TABLE IF NOT EXISTS playlist_youtube(
# song_id INTEGER PRIMARY KEY,
# youtube_link TEXT)"""
# )
conn.execute("""CREATE TABLE IF NOT EXISTS playlist_song_type(
song_id INTEGER PRIMARY KEY,
song_type TEXT)"""
)
except Error as e:
print(e)
if __name__ == '__main__':
conn = create_connection("playlist.sqlite3")
print("Opening workbook...")
filename = 'playlist.xlsx'
wb = openpyxl.load_workbook(filename)
sheet = wb.get_active_sheet()
print(sheet)
print("Reading rows")
create_table(conn)
# for row in range(2, sheet.max_row + 1):
i = 1
for row in range(sheet.max_row, 1, -1):
print(row, sheet['A' + str(row)].value,\
sheet['A' + str(row)].fill.start_color.index,\
sheet['A' + str(row)].font.i)
# conn.execute("""INSERT INTO playlist
# (song_id, song_name)
# values(?, ?)""", (i, sheet['A' + str(row)].value))
# conn.execute("""INSERT INTO playlist
# (megasync_bool, memorycard_bool, youtube_bool)
# values(?, ?, ?)
# WHERE song_id=i""", ())
# conn.execute("""INSERT INTO playlist_youtube
# (song_id)
# values(?) """, (i, ))
'''
LEGEND:
if font.i is TRUE: type == METAL_INSTRUMENTAL
if fill.start_color_index = FFC6EFCE: song in SPTFY_PLIST_PFM and
type==METAL
if fill.start_color_index = FFFFFFCC: song in SPTFY_PLIST_MM and
type==NON_METAL
if fill.start_color_index = FFF2F2F2: type==METAL
'''
if sheet['A'+ str(row)].font.i is True:
type_ = "METAL_INSTRUMENTAL"
elif sheet['A'+ str(row)].fill.start_color.index\
is "FFC6EFCE" or "FFF2F2F2":
type_ = "METAL"
elif fill.start_color.index is "FFFFFFCC":
type_ = "NON_METAL"
print(type_)
conn.execute("""INSERT INTO playlist_song_type
(song_id, song_type)
values(?, ?) """, (i, type_))
i+=1
conn.commit()
conn.close()