def get_products(self) -> dict: """ Method to read and return the shopping data from a SQLite file database :param :return: dict """ products = dict() db = Database() db.create_connection(self._file_path) rows = db.get_products() db.close_connection() for row in rows: if row[0] not in products: try: products[row[0]] = Product(row[0], row[1], row[2], row[3]) # code, price, lastupdate, currency except Exception as e: # IF the database was not correct parsed, the item will be discarted, # the event will be logged in the log file and the program will continue logging.error(str(datetime.now())+': ' + e) continue return products
#!/usr/bin/env python """create_db.py: Script to populate simple SQLite database.""" __author__ = "Matias A. K. Schimuneck" __copyright__ = "Copyright 2019, Blueface - Dublin" import sys sys.path.append('../') from lib.database import Database if __name__ == '__main__': db = Database() db.create_connection("../tests/data.db") sql_create_table = """CREATE TABLE IF NOT EXISTS products ( code text PRIMARY KEY, price real NOT NULL, lastupdate text, currency text );""" db.create_table(sql_create_table) product_a = ('a', 1.0, '10-09-2019', 'EUR') product_b = ('b', 1.1, '10-09-2019', 'EUR') product_c = ('c', 1.173, '10-09-2019', 'EUR') product_d = ('d', 2.233, '10-09-2019', 'EUR') product_e = ('e', 3.0, '10-09-2019', 'EUR')