-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase_updater.py
39 lines (32 loc) · 1.04 KB
/
database_updater.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
import sqlite3
import scrapper
import images_links
con = sqlite3.connect('db\database.db')
# cursor object
cur = con.cursor()
# Drop the rocket_engines table if already exists.
cur.execute("DROP TABLE IF EXISTS rocket_engines")
titles, engines = scrapper()
images, wikipedia_pages = images_links()
# Creating table
table = """ CREATE TABLE rocket_engines (Id INTEGER NOT NULL PRIMARY KEY, """
for i in range(len(titles)):
table += f"""'{titles[i]}'"""
if type(engines[19][i]) == str:
table += """ TEXT, """
elif type(engines[19][i]) == float:
table += """ REAL, """
table = table.removesuffix(""", """)
table += """, Image TEXT); """
cur.execute(table)
print("Table is Ready")
print("Filling the database...")
for i in range(len(engines)):
cur = con.cursor()
cur.execute(f"INSERT INTO rocket_engines VALUES {(i, ) + engines[i] + (images[i], )};".replace("''", "NULL"))
con.commit()
print(f"{int(100 * (i/len(engines)))}% done")
print(f'100% done')
print("Table successfully filled")
# Close the connection
con.close()