Initial Commit
This commit is contained in:
parent
9d7abea63e
commit
e25466aa77
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
*.db
|
||||||
54
app.py
Normal file
54
app.py
Normal file
@ -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()
|
||||||
Loading…
x
Reference in New Issue
Block a user