From caf18fc0526874bb098b96e53328263624701f85 Mon Sep 17 00:00:00 2001 From: Florian Lutz Date: Tue, 3 Sep 2024 09:12:28 +0200 Subject: [PATCH] create database --- fake_news_checker.db | Bin 0 -> 12288 bytes src/utils/database/database.py | 54 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 fake_news_checker.db create mode 100644 src/utils/database/database.py diff --git a/fake_news_checker.db b/fake_news_checker.db new file mode 100644 index 0000000000000000000000000000000000000000..e06e2636198e68ab59cb797b30cc80155d1a06fa GIT binary patch literal 12288 zcmeI&O-{l<6bJB`R{RQzJ66Qmm_Se(MO?VDn9&eRK`e=^NWmdCmh#aO-5O8gG4vK* z#S=KK)C5=%S0?8F(wS+eZ(ft%?j^msHk?4P-eBCf16CwEgi>o00Izz00bZa0SG_<0uX=z1b!t@S60*cJZ%Mb#})p_ zm2GU>7o&;ry7Q0fd4uZ~XO>}5JKmY;|fB*y_009U< z00Izzz~2ZIlmw~nZrlgK&_C6*u&)o>`a*Zm*X(iNbX}nxmrgF^J~QQu1DYUwZ#~Wz zPj-LkiYPriryU*@`S)Iw9`^q<^-1J~fB*y_009U<00Izz00bZa0SG|g-v}hBnxXOE G3(6OI>WB{j literal 0 HcmV?d00001 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'}") -- 2.34.1