Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

34 implement data storage functionality #91

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions database.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# creating the database schema > database.py
import sqlite3

def create_database_schema():
Expand All @@ -17,4 +16,18 @@ def create_database_schema():
''')

connection.commit()
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()