Document 4
Document 4
import csv
class DatabaseConnector:
self.connection = sqlite3.connect(database_file)
self.cursor = self.connection.cursor()
reader_0 = csv.reader(file_0)
reader_1 = csv.reader(file_1)
reader_2 = csv.reader(file_2)
self.populate_shipping_data_1(reader_0)
self.populate_shipping_data_2(reader_1, reader_2)
if row_idx> 0:
product_name = row[2]
product_quantity = row[4]
origin = row[0]
destination = row[1]
self.insert_product(product_name)
shipment_info = {}
if row_idx > 0:
shipment_identifier = row[0]
origin = row[1]
destination = row[2]
shipment_info[shipment_identifier] = {
"origin": origin,
"destination": destination,
"products": {}
shipment_identifier = row[0]
product_name = row[1]
products = shipment_info[shipment_identifier]["products"]
products[product_name] = products.get(product_name, 0) + 1
origin = shipment_info[shipment_identifier]["origin"]
destination = shipment_info[shipment_identifier]["destination"]
self.insert_product(product_name)
query = '''
VALUES(?);
'''
self.cursor.execute(query, (product_name,))
self.connection.commit()
query = '''
SELECT id
FROM product
WHERE product.name = ?;
'''
self.cursor.execute(query, (product_name,))
product_id = self.cursor.fetchone()[0]
query = '''
VALUES(?,?,?,?);
'''
self.connection.commit()
def close(self):
self.connection.close()
if __name__ == '__main__':
db_connector = DatabaseConnector("shipment_database.db")
db_connector.populate("./data")
db_connector.close()