From b65bd034f7178acc1f3c8d108038f15ec6bd9895 Mon Sep 17 00:00:00 2001 From: AssahBismarkabah Date: Mon, 27 Nov 2023 09:46:03 +0100 Subject: [PATCH] feature(backend) added data-storage-functionality --- database.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/database.py b/database.py index b455f6a..db056c8 100644 --- a/database.py +++ b/database.py @@ -1,4 +1,4 @@ -# creating the database schema > database.py +# database.py import sqlite3 def create_database_schema(): @@ -17,4 +17,20 @@ def create_database_schema(): ''') connection.commit() - connection.close() \ No newline at end of file + connection.close() + +def store_analysis_results_in_database(results): + connection = sqlite3.connect('analysis_results.db') + cursor = connection.cursor() + + try: + for result in results: + cursor.execute(''' + INSERT INTO analysis_results (url, number_of_text, total_text, number_of_images) + VALUES (?, ?, ?, ?) + ''', (result['url'], len(result['text']), len(result['total_text']), len(result['images']))) + except sqlite3.Error as e: + print(f"SQLite error: {e}") + finally: + connection.commit() + connection.close()