fix database
This commit is contained in:
parent
1d962c388f
commit
c41b37e045
Binary file not shown.
|
@ -21,7 +21,6 @@ class MainFrameController:
|
|||
self.frame = frame
|
||||
self.model_inference = VeraMindInference('VeraMind-Mini')
|
||||
self.db = FakeNewsChecker()
|
||||
self._fetch_db_data()
|
||||
self.update_provider_list()
|
||||
|
||||
def get_text_data(self) -> TextData:
|
||||
|
@ -69,7 +68,7 @@ class MainFrameController:
|
|||
:param text_data: TextData object containing the analyzed information
|
||||
"""
|
||||
|
||||
self.db.insert_data(url=text_data.url, anbieter=text_data.get_provider(), is_fake_news=text_data.is_fake_news)
|
||||
self.db.insert_data(url=text_data.url, anbieter=text_data.get_provider(),is_fake_news= text_data.is_fake_news)
|
||||
|
||||
def _fetch_db_data(self):
|
||||
self.text_data_list = []
|
||||
|
|
|
@ -10,7 +10,8 @@ class Provider():
|
|||
count_all = 0
|
||||
count_fake = 0
|
||||
for text_data in self.text_data_list:
|
||||
print(text_data.is_fake_news)
|
||||
#print(text_data.provider)
|
||||
#print("FAKE" if text_data.is_fake_news else "REAL")
|
||||
count_all += 1
|
||||
if text_data.is_fake_news:
|
||||
count_fake += 1
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import sqlite3
|
||||
import duckdb
|
||||
|
||||
class FakeNewsChecker:
|
||||
def __init__(self, db_name='fake_news_checker.db'):
|
||||
|
@ -6,49 +6,50 @@ class FakeNewsChecker:
|
|||
self.create_table()
|
||||
|
||||
def create_connection(self):
|
||||
return sqlite3.connect(self.db_name)
|
||||
return duckdb.connect(self.db_name)
|
||||
|
||||
def create_table(self):
|
||||
conn = self.create_connection()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''
|
||||
conn.execute('''
|
||||
CREATE TABLE IF NOT EXISTS url_info (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
url TEXT NOT NULL,
|
||||
anbieter TEXT NOT NULL,
|
||||
id INTEGER PRIMARY KEY,
|
||||
url VARCHAR NOT NULL,
|
||||
anbieter VARCHAR NOT NULL,
|
||||
is_fake_news BOOLEAN NOT NULL
|
||||
)
|
||||
''')
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
def get_next_id(self):
|
||||
conn = self.create_connection()
|
||||
result = conn.execute('SELECT COALESCE(MAX(id), 0) + 1 FROM url_info').fetchone()
|
||||
conn.close()
|
||||
return result[0]
|
||||
|
||||
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()
|
||||
next_id = self.get_next_id()
|
||||
conn.execute('''
|
||||
INSERT INTO url_info (id, url, anbieter, is_fake_news)
|
||||
VALUES (?, ?, ?, ?)
|
||||
''', [next_id, url, anbieter, bool(is_fake_news)])
|
||||
conn.close()
|
||||
|
||||
def fetch_data(self):
|
||||
conn = self.create_connection()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('SELECT * FROM url_info')
|
||||
rows = cursor.fetchall()
|
||||
result = conn.execute('SELECT * FROM url_info').fetchall()
|
||||
conn.close()
|
||||
return rows
|
||||
return result
|
||||
|
||||
# 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)
|
||||
checker.insert_data('https://example.com/news/123', 'Example News', False)
|
||||
checker.insert_data('https://fakenews.com/article/456', 'Fake News', True)
|
||||
|
||||
# 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'}")
|
||||
print(f"ID: {row[0]}, URL: {row[1]}, Anbieter: {row[2]}, Fake News: {'Ja' if row[3] else 'Nein'}")
|
Loading…
Reference in New Issue