commit message from python script

This commit is contained in:
2023-11-28 20:24:45 +01:00
parent 0f184cfcf3
commit 02388c80de
3 changed files with 34 additions and 17 deletions

View File

@@ -6,6 +6,7 @@ class db_work:
self.script_folder = os.path.dirname(os.path.realpath(__file__)) self.script_folder = os.path.dirname(os.path.realpath(__file__))
def create_db(self): def create_db(self):
if not os.path.exists(self.db_file):
with sqlite3.connect(self.db_file) as con_db: with sqlite3.connect(self.db_file) as con_db:
cursor = con_db.cursor() cursor = con_db.cursor()
sql_code = """ sql_code = """
@@ -14,6 +15,7 @@ class db_work:
'name' TEXT, 'name' TEXT,
'filmgenres' TEXT, 'filmgenres' TEXT,
'year' TEXT, 'year' TEXT,
'format',
'persönlich' TEXT 'persönlich' TEXT
); """ ); """
cursor.execute(sql_code) cursor.execute(sql_code)
@@ -24,7 +26,7 @@ class db_work:
'beschreibung' TEXT 'beschreibung' TEXT
); """ ); """
cursor.execute(sql_code) cursor.execute(sql_code)
if not os.path.exists(self.db_file):
sql_code = """ sql_code = """
INSERT INTO filmgenres(genre, beschreibung) INSERT INTO filmgenres(genre, beschreibung)
VALUES VALUES
@@ -34,17 +36,22 @@ INSERT INTO filmgenres(genre, beschreibung)
( 'drama', 'Das Drama ist nach antiker Definition eine Gattung der Dichtung und bezeichnet eine Handlung mit verteilten Rollen. '); ( 'drama', 'Das Drama ist nach antiker Definition eine Gattung der Dichtung und bezeichnet eine Handlung mit verteilten Rollen. ');
""" """
cursor.execute(sql_code) cursor.execute(sql_code)
con_db.commit() con_db.commit()
return "db create"
else:
return "db exists"
def add_value_db(self): def add_value_db(self):
with sqlite3.connect(self.db_file) as con_db: with sqlite3.connect(self.db_file) as con_db:
cursor = con_db.cursor() cursor = con_db.cursor()
while True: while True:
##Abfrage Name
name = input("Name des Films: ") name = input("Name des Films: ")
if not name: if not name:
break break
##Abfrage Genre
while True: while True:
movie_genre = input("Genre: ") movie_genre = input("Genre: ")
sql = """Select * from filmgenres where genre = '{genre}'""".format(genre=movie_genre) sql = """Select * from filmgenres where genre = '{genre}'""".format(genre=movie_genre)
cursor.execute(sql) cursor.execute(sql)
@@ -57,26 +64,36 @@ INSERT INTO filmgenres(genre, beschreibung)
print("Folgende Genres sind angelegt :") print("Folgende Genres sind angelegt :")
self.ausgabe_abfrage(sql_abfrage="""Select genre from filmgenres""") self.ausgabe_abfrage(sql_abfrage="""Select genre from filmgenres""")
###########if movie_genre #Abfrage Jahr
movie_year = input("Jahr: ") movie_year = input("Jahr: ")
#Abfrage Format
while True:
format = input("Format :")
if format == "blue-ray" or format == "dvd" or format == "platte" or format == "sd":
break
else:
print("blue-ray", "dvd", "platte", "sd")
#Abfrage Meinung
per_info = input("Meinung : ") per_info = input("Meinung : ")
sql = """Select * from movies WHERE name = '{name}';""".format(name=name) sql = """Select * from movies WHERE name = '{name}';""".format(name=name)
cursor.execute(sql) cursor.execute(sql)
if not cursor.fetchone(): if not cursor.fetchone():
print("Film wird angelgt ") print("Film wird angelgt ")
self.speicher_aktion(movie=name, filmgenre=movie_genre, year=movie_year, persönlich=per_info) self.speicher_aktion(movie=name, filmgenre=movie_genre, year=movie_year, persönlich=per_info, format=format)
else: else:
print("Film bereits vorhanden !") print("Film bereits vorhanden !")
print("Eingabevorgang wurde beendet.") print("Eingabevorgang wurde beendet.")
def speicher_aktion(self, movie = str, filmgenre = str, year = str, persönlich = str): def speicher_aktion(self, movie = str, filmgenre = str, year = str, persönlich = str, format = str):
with sqlite3.connect(self.db_file) as verbindung: with sqlite3.connect(self.db_file) as verbindung:
cursor = verbindung.cursor() cursor = verbindung.cursor()
sql = """INSERT INTO movies(name, filmgenres, year, 'persönlich' ) sql = """INSERT INTO movies(name, filmgenres, year, format, 'persönlich' )
VALUES ( '{movie}', '{filmgenre}', '{year}', '{persönlich}' );""".format( VALUES ( '{movie}', '{filmgenre}', '{year}', '{format}','{persönlich}' );""".format(
movie=movie, movie=movie,
filmgenre=filmgenre, filmgenre=filmgenre,
year=year, year=year,
format = format,
persönlich=persönlich) persönlich=persönlich)
cursor.execute(sql) cursor.execute(sql)
@@ -100,7 +117,7 @@ if __name__ == "__main__":
script_folder = os.path.dirname(os.path.realpath(__file__)) script_folder = os.path.dirname(os.path.realpath(__file__))
db_file_full = script_folder + os.sep + "my_moviedb.db" db_file_full = script_folder + os.sep + "my_moviedb.db"
my_db = db_work(db_file=db_file_full) my_db = db_work(db_file=db_file_full)
my_db.create_db() print(my_db.create_db())
for query in argv.sys.argv[1:]: for query in argv.sys.argv[1:]:
if query == '-q': if query == '-q':

BIN
my_movies/my_moviedb.db Normal file

Binary file not shown.

View File