From e25466aa7732c2cb3c8c60f07cd12dd3386c4a20 Mon Sep 17 00:00:00 2001 From: jordan Date: Sat, 10 Dec 2022 22:59:07 +1100 Subject: [PATCH] Initial Commit --- .gitignore | 1 + app.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ tool.py | 0 3 files changed, 55 insertions(+) create mode 100644 .gitignore create mode 100644 app.py create mode 100644 tool.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3997bea --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.db \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..9cdc60d --- /dev/null +++ b/app.py @@ -0,0 +1,54 @@ +""" Tool to select random movies from our to watch database """ +import sqlite3 + +#connection = sqlite3.connect("data.db") + +def create_table(): + """ Function to create new table if none already exists""" + with sqlite3.connect("data.db") as connection: + connection.execute("CREATE TABLE IF NOT EXISTS movies (title TEXT, genre TEXT, year INT)," \ + "UNIQUE(title));") + # close_connection() + +def add_movie(title, genre, year): + """ Function for adding movies to the db""" + with sqlite3.connect("data.db") as connection: + connection.execute("INSERT OR IGNORE INTO movies VALUES (?, ?, ?)", (title, genre, year)) + # close_connection() + +def select_random_movie(): + """ Function for selecting random movie """ + with sqlite3.connect("data.db") as connection: + rand_mov_list = connection.execute("SELECT * FROM movies ORDER BY RANDOM() LIMIT 1;") + for movie in rand_mov_list: + movie_name = (f"{movie[0]}, from {movie[2]}") + return movie_name + +def main(): + """ This is the main function of the script""" + print('Please enter your choice...') + main_prompt = (''' + **************************** + 1: Enter a movie + 2: Get random movie + 3: Exit + **************************** + ''') + while (user_input := input(main_prompt)) != "3": + if user_input == "1": + print("Adding movie") + movie_title = input("Enter Title: ") + movie_genre = input("Enter Genre: ") + movie_year = input("Enter Year: ") + add_movie(movie_title, movie_genre, movie_year) + print("Movie Added") + continue + if user_input == "2": + print("Selecting Movie...") + random_movie = select_random_movie() + print(f"Let's watch {random_movie}") + continue + print("Invalid option, please try again") + + +main() diff --git a/tool.py b/tool.py new file mode 100644 index 0000000..e69de29