|
|
|
|
|
|
|
|
|
|
|
import sqlite3 |
|
|
|
|
|
import pandas as pd |
|
|
|
|
|
from sqlite3 import Error |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
questions = [('Wie heißt der längst Fluss auf der Welt?', 'Amazonas', 'Nil', 'Jangtsekiang', 'Nil'), |
|
|
|
|
|
('Aus welcher englischen Stadt stammt die Musikgruppe die Beatles?', 'London', 'Sheffield', 'Liverpool', 'Liverpool'), |
|
|
|
|
|
('Zu welchem Land gehört Grönland?', 'Norwegen', 'Island', 'Dänemark', 'Dänemark'), |
|
|
|
|
|
('Wie heißen die ursprünglichen Bewohner Australiens?', 'Aborigines', 'Eingeborene', 'Australian Natives', 'Aborigines'), |
|
|
|
|
|
('Mit welchem Korn verglich Jesus das Reich Gottes?', 'Senfkorn', 'Weizenkorn', 'Haferkorn', 'Senfkorn'), |
|
|
|
|
|
('Wie lange können Kaiserpinguine tauchen?', '5min', '10min', '20min', '20min'), |
|
|
|
|
|
('Wer war der Kommandant der Apollo 11?', 'Louis Armstrong', 'Neil Armstrong', 'Lance Armstrong', 'Neil Armstrong'), |
|
|
|
|
|
('Wie heißt die größte Stadt der Welt (nach Einwohnern)?', 'São Paulo', 'Tokio', 'Seoul', 'Tokio',), |
|
|
|
|
|
('In welchem Land liegt Helsinki?', 'Finnland', 'Norwegen', 'Schweden', 'Finnland'), |
|
|
|
|
|
('Wie viele Bundesländer hat Deutschland?', '16', '17', '20', '16'), |
|
|
|
|
|
('Wie heißt der höchste Berg Europas?', 'Zugspitze', 'Matterhorn', 'Montblanc', 'Montblanc'), |
|
|
|
|
|
('Wie lange braucht das Licht in etwa von der Sonne zur Erde?', '80 Sekunden', '8 Minuten', '7 Tage', '8 Minuten'), |
|
|
|
|
|
('Was hat James Watt erfunden?', 'Glühbirne', 'Elektrischen Widerstand', 'Dampfmaschine', 'Dampfmaschine'), |
|
|
|
|
|
('Wie hieß der erste Deutsch Bundeskanzler?', 'Helmut Schmidt', 'Konrad Adenauer', 'Willy Brandt', 'Konrad Adenauer'), |
|
|
|
|
|
('Von wem stammt das Gemälde der Mona Lisa?', 'Picasso', 'Vincent van Gogh', 'Leonardo da Vinci', 'Leonardo da Vinci'), |
|
|
|
|
|
('Wie heißt der Erfinder der Jeanshose?', 'Tom Wrangler', 'Levi Strauss', 'Peter Diesel', 'Levi Strauss'), |
|
|
|
|
|
('Welches Land gewann 2014 die Fußball Weltmeisterschaft?', 'Brasilien', 'Argentien', 'Deutschland', 'Deutschland'), |
|
|
|
|
|
('Welcher ist der "rote Planet" unseres Sonnensystems?', 'Mars', 'Venus', 'Jupiter', 'Mars'), |
|
|
|
|
|
('Was bezeichnet die chemische Formel \'NaCl\'?', 'Kochsalz', 'Wasser', 'Stickstoff', 'Kochsalz'), |
|
|
|
|
|
('Welche Form hat die Narbe auf Harry Potters Stirn?', 'Dreieck', 'Blitz', 'Kreuz', 'Blitz')] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class QuestionDataBase: |
|
|
|
|
|
def __init__(self, file_name) -> None: |
|
|
|
|
|
self.file_name = file_name |
|
|
|
|
|
try: |
|
|
|
|
|
self.connection = sqlite3.connect(database=self.file_name) |
|
|
|
|
|
print(f'Successfully connected to SQLite (Version: ' + sqlite3.version + ')..\n') |
|
|
|
|
|
except Error as err: |
|
|
|
|
|
print(err) |
|
|
|
|
|
self.cursor = self.connection.cursor() |
|
|
|
|
|
|
|
|
|
|
|
def close_connection(self): |
|
|
|
|
|
try: |
|
|
|
|
|
self.cursor.close() |
|
|
|
|
|
print("Close connection to SQLite was successfully.") |
|
|
|
|
|
except Error as err: |
|
|
|
|
|
print(err) |
|
|
|
|
|
|
|
|
|
|
|
def create_table(self): |
|
|
|
|
|
table_config = "CREATE TABLE IF NOT EXISTS Questions" \ |
|
|
|
|
|
"(QuestionNr TEXT PRIMARY KEY," \ |
|
|
|
|
|
" Answeroption_1 \nTEXT," \ |
|
|
|
|
|
" Answeroption_2 TEXT," \ |
|
|
|
|
|
" Answeroption_3 TEXT," \ |
|
|
|
|
|
" Correct_answeroption TEXT)" |
|
|
|
|
|
self.cursor.execute(table_config) |
|
|
|
|
|
print("Successfully create tables.. ") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def insert_table(self, questions: list): |
|
|
|
|
|
self.cursor.executemany("INSERT OR IGNORE INTO Questions VALUES (?, ?, ?, ?, ?)", questions) |
|
|
|
|
|
print("Successfully insert data into table.") |
|
|
|
|
|
|
|
|
|
|
|
def num_rows(self): |
|
|
|
|
|
self.cursor.execute("SELECT COUNT(*) FROM Questions") |
|
|
|
|
|
return self.cursor.fetchone()[0] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def delete_data(self, table_name): |
|
|
|
|
|
self.cursor.execute(f"DELETE FROM {table_name}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def read_question_data(self, file_name: str): |
|
|
|
|
|
try: |
|
|
|
|
|
data = pd.read_csv(file_name, delimiter=';') |
|
|
|
|
|
except Error as err: |
|
|
|
|
|
print('File could not be read..') |
|
|
|
|
|
print(err) |
|
|
|
|
|
return data |
|
|
|
|
|
|
|
|
|
|
|
## ToDO: get question, return type(dict) |
|
|
|
|
|
def get_questions(): |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
|
|
|
|
|
|
|
|
database = QuestionDataBase('Project/BackEnd/Database/EinsZweiOderDrei.db') |
|
|
|
|
|
insert_table = database.insert_table(questions) |
|
|
|
|
|
|
|
|
|
|
|
database.commit() |
|
|
|
|
|
database.close_connection() |
|
|
|
|
|
|