69 lines
2.2 KiB
Python
69 lines
2.2 KiB
Python
import pandas as pd
|
|
import sys
|
|
import sqlite3
|
|
|
|
'''
|
|
When this init file is used for projects, the location should be passed as an argument, similar to:
|
|
|
|
%run jeplinit.py resources/JEPL/jepl/
|
|
|
|
If there is no argument, we assume that it is part of development and we will use the root folder.
|
|
'''
|
|
location = ''
|
|
if sys.argv[1]:
|
|
location = sys.argv[1] # This needs to be passed if its not the same as the location of jepl.py
|
|
|
|
|
|
'''
|
|
The functions used in the initialization
|
|
'''
|
|
|
|
def insert(database,table,data):
|
|
'''
|
|
This function creates a database from the current
|
|
source data to be used in the modules.
|
|
|
|
Running this function will replace any data that is already in the database.
|
|
'''
|
|
|
|
conn = sqlite3.connect(database)
|
|
data.to_sql(table, conn, if_exists='replace', index=False)
|
|
conn.close()
|
|
|
|
def create_database(name,tables):
|
|
'''
|
|
This function loops over the source data lists to create tables in the database.
|
|
'''
|
|
|
|
for i in range(len(tables)):
|
|
db = tables[i][0]
|
|
table = tables[i][1]
|
|
source = tables[i][2]
|
|
data = pd.read_csv(source)
|
|
|
|
insert(db,table,data) # Call the database insert function to add the data
|
|
|
|
|
|
'''
|
|
This is all the tables and their sources that will be added to the databases.
|
|
|
|
'''
|
|
|
|
CEC21_database = [
|
|
['jepl-cec21.db','Table1',location+'Tables/CEC-Tables/CEC21-table1.csv'],
|
|
['jepl-cec21.db','Table2',location+'Tables/CEC-Tables/CEC21-table2.csv'],
|
|
['jepl-cec21.db','Table3',location+'Tables/CEC-Tables/CEC21-table3.csv'],
|
|
['jepl-cec21.db','Table4',location+'Tables/CEC-Tables/CEC21-table4.csv'],
|
|
['jepl-cec21.db','Table9',location+'Tables/CEC-Tables/CEC21-table9.csv'],
|
|
['jepl-cec21.db','Table16',location+'Tables/CEC-Tables/CEC21-table16.csv'],
|
|
]
|
|
create_database('jepl-cec21.db',CEC21_database)
|
|
|
|
|
|
|
|
cable_database = [
|
|
['jepl-cable.db','SW-Spec 25055',location+'Tables/Manufacturer/SW-Spec-25055.csv'],
|
|
['jepl-cable.db','SW-Spec 25051',location+'Tables/Manufacturer/SW-Spec-25051.csv'],
|
|
]
|
|
create_database('jepl-cable.db',cable_database)
|
|
|