-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopulate_database.py
25 lines (22 loc) · 980 Bytes
/
populate_database.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
# This file is part of the Silence framework.
# Silence was developed by the IISSI1-TI team
# (Agustín Borrego, Daniel Ayala, Carlos Ortiz, Inma Hernández & David Ruiz)
# and it is distributed as open source software under the GNU-GPL 3.0 License.
from dal.database.db_connection import get_conn
# Method for destroying and creating the database tables
# This shouldn't be modified, it uses the create_database.sql file
def create_database(verbose=False):
conn = get_conn()
cursor = conn.cursor()
with open("create_database.sql", "r", encoding="utf-8") as f:
for stmt in f.read().split(";"):
if not stmt or stmt.strip() == "": continue # Skip blank lines
if verbose: print(stmt + ";")
cursor.execute(stmt)
conn.commit()
cursor.close()
#######################################
if __name__ == "__main__":
print("Creating and populating the database...")
create_database(verbose=True)
print("Success!")