commit message from python script

This commit is contained in:
2023-11-15 17:18:45 +01:00
parent a07d37388e
commit 95bc2ebe2e
5 changed files with 41 additions and 33 deletions

View File

@@ -1,5 +0,0 @@
CREATE TABLE IF NOT EXISTS eggs(
cooler_typ TEXT PRIMARY KEY,
glückszahl INTEGER
);

View File

@@ -7,38 +7,51 @@ class db_work:
def create_db(self):
with sqlite3.connect(self.db_file) as con_db:
cursor = con_db.cursor()
fd = open(self.script_folder + os.sep + "create_db.sql", "r")
sql_code = fd.read()
#sql_code = '''
# CREATE TABLE IF NOT EXISTS eggs(
# cooler_typ TEXT,
# glückszahl INTEGER
# );
# '''
sql_code = """
CREATE TABLE IF NOT EXISTS movies(
'id' INTEGER AUTOINCREMENT,
'name' TEXT PRIMARY KEY,
'filmgenres' TEXT,
'year' TEXT,
'persönlich' TEXT
); """
cursor.execute(sql_code)
sql_code = """
CREATE TABLE IF NOT EXISTS filmgenres(
'genre' TEXT PRIMARY KEY,
'beschreibung' TEXT
); """
cursor.execute(sql_code
)
con_db.commit()
def add_value_db(self, cooler_typ = str, glueckszahl = int):
def add_value_db(self):
with sqlite3.connect(self.db_file) as con_db:
cursor = con_db.cursor()
fd = open(self.script_folder + os.sep + "add_value.sql", "r")
sql_code = fd.read().format(coolertype=cooler_typ,eine_zahl=glueckszahl)
while True:
name = input("Name des Films: ")
if not name:
break
movie_genre = input("Genre: ")
movie_year = input("Jahr: ")
per_info = input("Meinung : ")
sql = """Select * from movies WHERE name = '{name}';""".format(name=name)
cursor.execute(sql)
if not cursor.fetchone():
print("Film wird angelgt ")
#self.speicher_aktion(name, ort, vorfall)
else:
print("Film bereits vorhanden !")
print("Eingabevorgang wurde beendet.")
try:
cursor.execute(sql_code)
except sqlite3.IntegrityError:
return False
def speicher_aktion():
pass
con_db.commit()
return True
def show_value(self):
def show_value(self, sql_query = str):
with sqlite3.connect(self.db_file) as con_db:
cursor = con_db.cursor()
sql_code = '''
SELECT * FROM eggs;
'''
sql_code = sql_query
cursor.execute(sql_code)
ergebnis = cursor.fetchall()
return ergebnis
@@ -46,9 +59,9 @@ class db_work:
if __name__ == "__main__":
script_folder = os.path.dirname(os.path.realpath(__file__))
db_file_full = script_folder + os.sep + "spam.db"
db_file_full = script_folder + os.sep + "my_moviedb.db"
my_db = db_work(db_file=db_file_full)
my_db.create_db()
add_value_to_db = my_db.add_value_db(cooler_typ="daniel-5", glueckszahl=42)
print (add_value_to_db)
print(my_db.show_value())
add_value_to_db = my_db.add_value_db()
#print (add_value_to_db)
print(my_db.show_value(sql_query="""SELECT * FROM movies;"""))

0
my_movies/my_moviedb.db Normal file
View File

Binary file not shown.

Binary file not shown.