-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbookDatabaseSQL.py
More file actions
75 lines (56 loc) · 1.67 KB
/
bookDatabaseSQL.py
File metadata and controls
75 lines (56 loc) · 1.67 KB
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
import sqlite3
import pandas as pd
def createTables(con, cur):
cur.execute(
"""
CREATE TABLE IF NOT EXISTS read (
Title TEXT
Author TEXT
Series TEXT
Representation TEXT
Genre TEXT
Age TEXT
);
"""
)
cur.execute(
"""
CREATE TABLE IF NOT EXISTS tbr (
Title TEXT
Author TEXT
Series TEXT
Representation TEXT
Genre TEXT
Age TEXT
);
"""
)
con.commit()
def sqlStuff():
sqlDatabaseName = "books.db"
con = sqlite3.connect(sqlDatabaseName)
cur = con.cursor()
cur.execute("DROP TABLE tbr;")
excelFile = "Books.xlsx"
dfRead = pd.read_excel(excelFile, sheet_name="Read", header=0)
dfTBR = pd.read_excel(excelFile, sheet_name="TBR", header=0)
dfRecommendations = pd.read_excel(excelFile, sheet_name="Recommendations", header=0)
dfOwnedTBR = pd.read_excel(excelFile, sheet_name="Owned TBR", header=0)
#print(dfTBR)
createTables(con, cur)
dfRead.to_sql('read', con, if_exists='replace', index=False)
dfTBR.to_sql('tbr', con, if_exists='replace', index=False)
#pd.read_sql("SELECT * FROM tbr LIMIT 5", con)
cur.execute('''
SELECT Author, Title FROM tbr LIMIT 5''')
for row in cur.fetchall():
print (row)
cur.execute('''
SELECT Author, Title FROM read LIMIT 5''')
for row in cur.fetchall():
print (row)
con.close()
def main():
sqlStuff()
if __name__ == '__main__':
main()