diff --git a/fake_news_checker.db b/fake_news_checker.db new file mode 100644 index 0000000..e06e263 Binary files /dev/null and b/fake_news_checker.db differ diff --git a/src/utils/database/database.py b/src/utils/database/database.py new file mode 100644 index 0000000..00ede72 --- /dev/null +++ b/src/utils/database/database.py @@ -0,0 +1,54 @@ +import sqlite3 + +class FakeNewsChecker: + def __init__(self, db_name='fake_news_checker.db'): + self.db_name = db_name + self.create_table() + + def create_connection(self): + return sqlite3.connect(self.db_name) + + def create_table(self): + conn = self.create_connection() + cursor = conn.cursor() + cursor.execute(''' + CREATE TABLE IF NOT EXISTS url_info ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + url TEXT NOT NULL, + anbieter TEXT NOT NULL, + is_fake_news BOOLEAN NOT NULL + ) + ''') + conn.commit() + conn.close() + + def insert_data(self, url, anbieter, is_fake_news): + conn = self.create_connection() + cursor = conn.cursor() + cursor.execute(''' + INSERT INTO url_info (url, anbieter, is_fake_news) + VALUES (?, ?, ?) + ''', (url, anbieter, is_fake_news)) + conn.commit() + conn.close() + + def fetch_data(self): + conn = self.create_connection() + cursor = conn.cursor() + cursor.execute('SELECT * FROM url_info') + rows = cursor.fetchall() + conn.close() + return rows + +# Beispielnutzung der Klasse +if __name__ == '__main__': + checker = FakeNewsChecker() + + # Daten hinzufügen + checker.insert_data('https://example.com/news/123', 'Example News', 0) + checker.insert_data('https://fakenews.com/article/456', 'Fake News', 1) + + # Daten abrufen + data = checker.fetch_data() + for row in data: + print(f"ID: {row[0]}, URL: {row[1]}, Anbieter: {row[2]}, Fake News: {'Ja' if row[3] else 'Nein'}")