diff --git a/modules/Archive/databaseController.py b/modules/Archive/databaseController.py index 6b5466e..379bc8f 100644 --- a/modules/Archive/databaseController.py +++ b/modules/Archive/databaseController.py @@ -6,7 +6,7 @@ TABLE_X = "x_posts" class DatabaseController: def __init__(self, db_name): - self.conn = sqlite3.connect(db_name, isolation_level="DEFERRED") + self.conn = sqlite3.connect(db_name) self.cursor = self.conn.cursor() def run_query(self, query): @@ -18,15 +18,28 @@ class DatabaseController: print(e) return None - def run_command(self, commnd): + def run_command(self, command): try: - self.cursor.execute(commnd) + self.cursor.execute(command) result = self.cursor.rowcount self.conn.commit() return result > 0 except Exception as e: + self.conn.rollback() print(e) return False + def run_commands(self, commands): + try: + for command in commands: + self.cursor.execute(command) + result = self.cursor.rowcount + self.conn.commit() + return result > 0 + except Exception as e: + self.conn.rollback() + print(e) + return False + def close(self): self.conn.close() \ No newline at end of file diff --git a/modules/Archive/load_from_file.py b/modules/Archive/load_from_file.py new file mode 100644 index 0000000..6176829 --- /dev/null +++ b/modules/Archive/load_from_file.py @@ -0,0 +1,8 @@ +import sys +from databaseController import DatabaseController + +db = DatabaseController("/home/pi/python/Katbots/JapariArchive/database.db") +with open(sys.argv[1], "rt") as file: + lines = [line for line in file.readlines() if line.strip()] + +print(db.run_commands(lines))