def menu(): # ask for the users name user_name_input = input('Hello! Enter your name: ') print(user_name_input) # if it already exists, welcome them and load their data filename = '{}.txt'.format(user_name_input) if file_exists(filename): with open(filename, 'r') as file: json_data = json.load(file) user = User.user_from_json(json_data) # if not, create user object else: user = User(user_name_input) user_input = input("Enter 'a' to add a movie, " "'s' to see a list of movies," "'w' to set a movie as watched, " "'d' to delete a movie," "'l' to see the list of watched movies," " or 'q' to save and quit: ") while user_input != 'q': if user_input == 'a': movie_name = input('Enter a movie name: ') movie_genre = input('Enter the movie genre: ') user.add_movie(movie_name, movie_genre) elif user_input == 's': for movie in user.movies: print("Name: {}, Genre: {}, Watched: {}".format( movie.name, movie.genre, movie.watched)) elif user_input == 'w': movie_name = input('Enter the movie you have watched: ') user.set_watched(movie_name) elif user_input == 'd': movie_name = input('Enter the movie name to delete: ') user.delete_movie(movie_name) elif user_input == 'l': for movie in user.watched_movies(): print("Name: {}, Genre: {}, Watched: {}".format( movie.name, movie.genre, movie.watched)) user_input = input("Enter 'a' to add a movie, " "'s' to see a list of movies," "'w' to set a movie as watched, " "'d' to delete a movie," "'l' to see the list of watched movies," " or 'q' to save and quit: ") with open(filename, 'w') as file: json.dump(user.json(), file) # give them a list of options: # add a movie # see list of movies # set a movie as watched # delete a movie by name # see list of watched movies # save and quit pass
def menu(): # Ask for the user's name name = input('Enter your name: ') # Check if a file exists for that user filename = "{}.txt".format(name) if file_exists(filename): print('file exists') with open(filename, 'r') as f: json_data = json.load(f) user = User.json_load(json_data) else: user = User(name) # If it already exists, welcome them and load their data # If not, create a User object # Give them a list of options # Add a movie # See list of movies # Set a movie as watched # Delete a movie by name # See list of watched movies # Save and quit user_input = input( 'Enter \'a\' to add a movie, \'w\' to set a movie as \'watched\', \'l\' to list movies' '\'s\' to see the list of watched movies, \'f\' to save ' '\'d\' to delete a movie or \'q\' to quit') while user_input != 'q': if user_input == "a": movie_name = input('Enter a name for the movie : \n') movie_genre = input('Enter a genre for the movie: \n') user.add_movie(movie_name, movie_genre, False) elif user_input == "w": movie_name = input( 'Enter the name of the movie to set as watched: \n') user.set_watched(movie_name) elif user_input == "l": for movie in user.movies: print("Name: {} Genre: {} Watched: {}".format( movie.name, movie.genre, movie.watched)) elif user_input == "d": movie_name = input('Enter the name of the movie to delete: \n') user.delete_movie(movie_name) elif user_input == "s": for movie in user.watched_movies: print("Name: {} Genre: {} Watched: {}".format( movie.name, movie.genre, movie.watched)) elif user_input == "f": with open(filename, "a") as f: if file_exists(filename): print('file exists') json.dump(user.to_json_existing(), f) else: json.dump(user.to_json(), f) user_input = input( 'Enter \'a\' to add a movie, \'w\' to set a movie as \'watched\', \'l\' to list movies' '\'s\' to see the list of movies, \'f\' to save ' '\'d\' to delete a movie or \'q\' to quit')
def menu(): name = input("What's your name?") filename = f"{name}.txt" if file_exists(filename): with open(filename, 'r') as f: json_data = json.load(f) user = User.from_json(json_data) else: user = User(name) print("Select what do you want to do!") print("1. Add a movie") print("2. See list of movies") print("3. Set a movie as watched") print("4. Delete a movie by name") print("5. See list of watched movies") print("6. Save") print("0. Quit") user_input = int(input("")) while user_input != 0: if user_input == 1: new_movie_name = input("Insert the name of the new movie:\n") new_movie_genre = input("Insert the genre of the new movie:\n") user.add_movie(new_movie_name, new_movie_genre) elif user_input == 2: for movie in user.movies: print( f"Name: {movie.name}, Genre: {movie.genre}, Watched: {movie.watched}" ) elif user_input == 3: movie_to_set = input("What movie do you want to set as watched?") user.set_watched(movie_to_set) elif user_input == 4: movie_to_delete = input("What movie do you want to delete?") user.delete_movie(movie_to_delete) elif user_input == 5: for movie in user.watched_movies(): print( f"Name: {movie.name}, Genre: {movie.genre}, Watched: {movie.watched}" ) if user_input == 6: with open(filename, 'w') as f: json.dump(user.json(), f) print("Select what do you want to do!") print("1. Add a movie") print("2. See list of movies") print("3. Set a movie as watched") print("4. Delete a movie by name") print("5. See list of watched movies") print("6. Save") print("0. Quit") user_input = int(input(""))
def menu(): # check user and create file if new user name = input("Please enter a username: "******"{}.txt".format(name) if file_exists(filename): with open(filename, 'r') as f: json_data = json.load(f) # need a real success / error message here print("Successfully loaded json from file!") user = User.from_json(json_data) print("Welcome back, {}!".format(user.name)) else: user = User(name) print("User successfully created! ", user) print('=' * 100) user_input = input( "'a' - Add a movie.\n's' - See list of movies.\n'w' - Set movie as watched.\n'd' - Delete a movie.\n'e' - List of watched movies.\n'q' - Exit the app.\nYour Selection: " ) print('=' * 100) while user_input != 'q': if user_input == 'a': name = input("Please enter the title of the movie: ") genre = input("Please enter the genre: ") user.add_movie(name, genre) with open(filename, 'w') as f: json.dump(user.json(), f) # need a real success / error message here print("Movie added successfully!") print('*' * 100) pass elif user_input == 's': for movie in user.movies: print('-' * 50) print("Name: {}\nGenre: {}\nWatched: {}".format( movie.name, movie.genre, movie.watched)) print('-' * 50) pass elif user_input == 'w': pass elif user_input == 'd': print(user.movies) name = input("Name of movie to delete: ") user.delete_movie(name) with open(filename, 'w') as f: json.dump(user.json(), f) # need a real success / error message here print("Movie deleted successfully!") print(user.movies) print('*' * 100) pass elif user_input == 'q': return print('=' * 100) user_input = input( "'a' - Add a movie.\n's' - See list of movies.\n'w' - Set movie as watched.\n'd' - Delete a movie.\n'e' - List of watched movies.\n'q' - Exit the app.\nYour Selection: " ) print('=' * 100)
def menu(): """Main interaction with application""" name = input("Please enter your name: ").lower() filename = f"storage/{name}.txt" # Create or Read a user instance (from file) if os.path.isfile(filename): with open(filename, 'r') as f: json_data = json.load(f) user = User.from_json(json_data) else: user = User(name) select_options = ( "\nSelect an option:\n'S' - See your list of movies.\n'W' - Mark a movie as Watched.\n'A' - Add a movie to " "your list of movies.\n'L' - List your watched movies.\n'D' - Delete a movie.\n'F' - Save " "updates.\n'Q' to save and quit: \n") user_input = input(select_options).lower() while True: if user_input == 's': print("\n") for movie in user.movies: print("Name: {} Genre: {} Watched: {}".format( movie.name, movie.genre, movie.watched)) elif user_input == 'w': movie_name = input( "\nEnter the movie title to set as watched: \n").lower() user.set_watched(movie_name) elif user_input == 'a': movie_name = input("\nEnter the movie title: \n").lower() movie_genre = input("Enter the movie genre: \n").lower() user.add_movie(movie_name, movie_genre) elif user_input == 'l': for movie in user.watched_movies(): print("Name: {} Genre: {} Watched: {}".format( movie.name, movie.genre, movie.watched)) elif user_input == 'd': movie_name = input( "Enter the movie title to be deleted: \n").lower() user.delete_movie(movie_name) elif user_input == 'f': user.save_file(filename) elif user_input == 'q': user.save_file(filename) break user_input = input(select_options).lower()
def menu(): #get users name; if the user file already exists, load that file, if it doesn't, create a new user name = input("Enter your name: ") filename = "{}.txt".format(name) if file_exists(filename): with open(filename, 'r') as f: json_data = json.load(f) user = User.from_json(json_data) else: user = User(name) #give user options to add movies, see list of movies, set movie as watched, delete movies, see watched movies, save a text json file or quit user_input = input( "Enter 'a' to add a movie, 's' to see the list of movies, 'w' to set a movie as watched, 'd' to delete a movie, 'l' to see the list of watched movies, 'f' to save or 'q' to quit: " ) while user_input != 'q': #if a, use the user class add movie object to add a user if user_input == 'a': movie_name = input("Enter the movie name: ") movie_genre = input("Enter the movie genre: ") user.add_movie(movie_name, movie_genre) #if s, pull up the user's movie list which is a list of movie objects and pull the movie properities from that list elif user_input == 's': for movie in user.movies: print("Name: {} Genre: {} Watched: {}".format( movie.name, movie.genre, movie.watched)) #if w, use the user method, set_watched, to change the value to set watched elif user_input == 'w': movie_name = input("Enter the movie name to set as watched: ") user.set_watched(movie_name) #if d, use the user method, delete_movie, to change delete the movie elif user_input == 'd': movie_name = input("Enter the movie name to delete: ") user.delete_movie(movie_name) #if l, cycle through the user list of watched movies (pulled up in the user method watched_movies) and print each movie object elif user_input == 'l': for movie in user.watched_movies(): print("Name: {} Genre: {} Watched: {}".format( movie.name, movie.genre, movie.watched)) #if f, save user file as a new text file using JSON to pass the data through the text file elif user_input == 'f': with open(filename, 'w') as f: json.dump(user.json(), f) # keep giving the user options until they quit user_input = input( "Enter 'a' to add a movie, 's' to see the list of movies, 'w' to set a movie as watched, 'd' to delete a movie, 'l' to see the list of watched movies, 'f' to save or 'q' to quit: " )
def menu(): name = input('pls input username:'******'{}.txt'.format(name) if file_exist(filename): user = User.load_from_json(filename) print('welcome back {}'.format(name)) print(user.movie) else: user = User(name) while True: print('---------') print('Add new movie: 1') print('See movies 2') print('See list movies watched 3') print('Delete movie 4') print('quit 5') select = input('select option') while select != '1' and select != '2' and select != '3' and select != '4' and select != '5': select = input('select option') if select == '1': while True: movieName = input('insert movie name: ') movieGenre = input('insert movie genre: ') user.add_movie(movieName, movieGenre) print('u inserted successfully') print(user.movie) c = input('do you want to continue ?') if c.lower().startswith('n'): break elif select == '2': print(user.movie) elif select == '3': print(user.wached_movie()) elif select == '4': delnum = 0 delName = input('input deleted movie:') for movie in user.movie: if movie.name == delName: delnum += 1 if delnum == 0: print('this movie name does not exist') else: user.del_movie(delName) print('you delete movie {}, number of movie deleted {}'.format( movie.name, delnum)) else: with open('{}.txt'.format(user.name), 'w') as f: json.dump(user.save_json(), f) print('you save data') break
def menu(): # Ask for user's name name = input("Enter your name: ") # Check if a file exists for user filename = "{}.txt".format(name) # If it exists, welcome them and load their data if file_exists(filename): with open(filename, 'r') as f: json_data = json.load(f) user = User.from_json(json_data) # If not, create a User object else: user = User(name) #Give them options: user_input = input( "What would you like to do? Type corresponding letter: \n a: Add a movie \n" " b: See list of movies \n c: See list of watched movies \n d: Delete a movie \n w: Set a movie as watched \n s: Save \n q: Quit \n" ) while user_input != 'q': # Add a movie if user_input == 'a': movie_name = input("Enter the movie name: ") movie_genre = input("Enter the movie genre: ") user.add_movie(movie_name, movie_genre) # See list of movies elif user_input == 'b': for movie in user.movies: print("Name: {}, Genre: {}, Watched: {}".format( movie.name, movie.genre, movie.watched)) # Set a movie as watched elif user_input == 'w': movie_name = input("Enter the movie name to set as watched: ") user.set_watched(movie_name) # Delete a movie by name elif user_input == 'd': movie_name = input("Enter the movie name to delete: ") user.delete_movie(movie_name) # See list of watched movies elif user_input == 'c': for movie in user.watched_movies(): print("Name: {}, Genre: {}, Watched: {}".format( movie.name, movie.genre, movie.watched)) # Save and quit elif user_input == 's': with open(filename, 'w') as f: json.dump(user.json(), f) user_input = input( "What would you like to do? Type corresponding letter: \n a: Add a movie \n" " b: See list of movies \n c: See list of watched movies \n d: Delete a movie \n w: Set a movie as watched \n s: Save \n q: Quit \n" )
def menu(): print("Welcome to the Movie Tracker 5000\n") filename = input("Enter your username: "******"Enter movie title: ") genre = input("Enter movie genre: ") user.add_movie(name, genre) elif user_input.lower() == 's': for movie in user.movies: print("Title: {name}\n" "Genre: {genre}\n" "Watched: {watched}\n\n".format(name=movie.name, genre=movie.genre, watched=movie.watched)) elif user_input.lower() == 'w': movie_name = input("Enter movie title: ") user.set_watched(movie_name) elif user_input.lower() == 'd': movie_name = input("Enter movie title to delete: ") user.delete_movie(movie_name) elif user_input.lower() == 'l': for movie in user.watched_movies(): print("Title: {name}\n" "Genre: {genre}\n" "Watched: {watched}\n\n".format(name=movie.name, genre=movie.genre, watched=movie.watched)) else: print("I didn't understand that command") user_input = get_menu_input() # Save file with open(filename, 'w') as f: json.dump(user.json(), f)
def menu(): name = input("Welcome to the Movie App! What is your name? ") filename = "{}.txt".format(name) if file_exists(filename): with open(filename, 'r') as f: json_data = json.load(f) user = User.from_json(json_data) else: user = User(name) user_input = input( "Enter 'a' to add a movie, 's' to see the list of movies, 'w' to set a movie as watched," "'d' to delete a movie, 'l' to see the list of watched movies, 'f' to save, or 'q' to " "quit") while user_input != 'q': if user_input == 'a': new_movie = input( "Enter the title of the movie you would like to add: ") new_genre = input("Now enter the movie's genre: ") new_watched = input("Have you watched this movie already? y/n: ") if new_watched == 'y': new_watched = True else: new_watched = False user.add_movie(new_movie, new_genre, new_watched) elif user_input == 's': for movie in user.movies: print("Name: {}, Genre: {}, Watched: {}".format( movie.name, movie.genre, movie.watched)) elif user_input == 'w': movie_name = input("Enter the movie name to set as watched") user.set_watched(movie_name) elif user_input == 'd': movie_name = input("Enter the movie name to delete: ") user.delete_movie(movie_name) elif user_input == 'l': for movie in user.watched_movies(): print("Name: {}, Genre: {}, Watched: {}".format( movie.name, movie.genre, movie.watched)) elif user_input == 'f': with open(filename, 'w') as f: json.dump(user.json(), f) user_input = input( "Enter 'a' to add a movie, 's' to see the list of movies, 'w' to set a movie as watched," "'d' to delete a movie, 'l' to see the list of watched movies, 'f' to save, or 'q' to " "quit")
def menu(): name = input("Enter your name: ") filename = "{}.txt".format(name) if file_exists(filename): with open(filename, 'r') as f: json_data = json.load(f) user = User.from_json(json_data) else: user = User(name) user_input = input( "Enter:\n 'a' to add a movie\n 'v' to view a list of movies\n " "'w' to set a movie as watched\n 'd' to delete a movie\n 'l' to see the list of watched movies\n" "' q' to save and quit\n") while user_input != 'q': if user_input == 'a': movie_name = input("Enter the movie name\n") movie_genre = input("Enter the movie genre\n") user.add_movie(movie_name, movie_genre) elif user_input == 'v': for movie in user.movies: print("Name: {} Genre: {} Watched: {}".format( movie.name, movie.genre, movie.watched)) print("\n") elif user_input == 'w': movie_name = input("Enter the movie to set as watched\n") user.set_watched(movie_name) print("\n") elif user_input == 'd': movie_name = input("Enter the movie name to delete:\n ") user.delete_movie(movie_name) elif user_input == 'l': for movie in user.watched_movies(): print("Name: {} Genre: {} Watched: {}".format( movie.name, movie.genre, movie.watched)) print("\n") elif user_input == 'f': with open(filename, "w") as f: json.dump(user.json(), f) #dump user's json into f user_input = input( "Enter:\n 'a' to add a movie\n 'v' to view a list of movies\n " "'w' to set a movie as watched\n 'd' to delete a movie\n 'l' to see the list of watched movies\n" "' f' to save and quit\n")
def menu(): name = input("Enter your name: ") filename = '{}.txt'.format(name) if file_exists(filename): with open(filename, 'r') as f: json_data = json.load(f) user = User.from_json(json_data) else: user = User(name) user_input = input( "Enter 'a' to add a movie, 's' to see the list of movies," "'w' to set a movie as watched, 'd' to delete a movie," "'l' to see the list of watched movies and 'q' to save and quit: \n") while True: if user_input == 'a': movie_name = input('Enter the movie name: ') movie_genre = input('Enter the movie genre: ') user.add_movie(movie_name, movie_genre) elif user_input == 's': for movie in user.movies: print("Name: {} Genre: {} Watched: {}".format( movie.name, movie.genre, movie.watched)) elif user_input == 'w': movie_name = input("Enter the movie name to set as watched: ") user.set_watched(movie_name) elif user_input == 'd': movie_name = input("Enter the movie name to delete: ") user.delete_movie(movie_name) elif user_input == 'l': for movie in user.watched_movies(): print("Name: {} Genre: {} Watched: {}".format( movie.name, movie_genre, movie.watched)) elif user_input == 'q': with open(filename, 'w') as f: json.dump(user.my_json(), f) break user_input = input( "Enter 'a' to add a movie, 's' to see the list of movies," "'w' to set a movie as watched, 'd' to delete a movie," "'l' to see the list of watched movies and 'q' to save and quit: \n" )
def menu(): # Ask for the user's name. name = input('Please enter your name: ') filename = f"{name}.txt" # Check if a file exists for that user. if file_exists(filename): # If it already exists, welcome them and load their data. with open(filename, 'r') as f: json_data = json.load(f) user = User.from_json(json_data) # If not, create a User object else: user = User(name) # Give them a list of options: selection = input("Enter 'a' to add a movie, 's' to see the list of movies," "'w' to set a movie as watched," "'d' to delete a movie, 'l' to see the list of watched movies," "'f' to save or 'q' to quit: ") while selection != 'q': if selection == 'a': movie_name = input("Enter the movie name: ") movie_genre = input("Enter movie genre: ") user.add_movie(movie_name, movie_genre) elif selection == 's': for movie in user.movies: print(f"Name: {movie.name} Genre: {movie.genre} Watched: {movie.watched}") elif selection == 'w': movie_name = input("Enter the movie to set as watched: ") user.set_watched(movie_name) elif selection == 'd': movie_name = input("Enter the movie you want to delete: ") user.delete_movie(movie_name) elif selection == 'l': for movie in user.watched_movies(): print(f"Name: {movie.name} Genre: {movie.genre} Watched: {movie.watched}") elif selection == 'f': with open(filename, 'w') as f: json.dump(user.json(), f) selection = input("Enter 'a' to add a movie, 's' to see the list of movies," "'w' to set a movie as watched," "'d' to delete a movie, 'l' to see the list of watched movies," "'f' to save or 'q' to quit: ")
def menu(): name = input('Enter your name ') filename = '{}.txt'.format(name) if file_exist(filename): with open(filename, 'r') as f: json_data = json.load(f) user = User.from_json(json_data) else: user = User(name) user_input = input('Enter \'a\' to add a movie,' ' \'s\' to see the list of movies,' ' \'w\' to set a movie as watched,' ' \'d\' to delete a movie,' ' \'l\' to see the list of watched movies,' ' \'f\' to save or ' ' \'q\' to quit') while user_input != 'q': if user_input == 'a': movie_name = input('Enter the movie name: ') movie_genre = input('Enter the movie genre: ') user.add_movie(movie_name, movie_genre) elif user_input == 's': for movie in user.movies: print('Name: {} Genre: {} Watched: {}'.format( movie.name, movie.genre, movie.watched)) elif user_input == 'w': movie_name = input('Enter the movie name to set as watched: ') user.set_watched(movie_name) elif user_input == 'd': movie_name = input('Enter the movie name to delete: ') user.delete_movie(movie_name) elif user_input == 'l': for movie in user.watched_movies(): print('Name: {} Genre: {} Watched: {}'.format( movie.name, movie.genre, movie.watched)) elif user_input == 'f': with open(filename, 'w') as f: json.dump(user.json(), f) user_input = input('Enter \'a\' to add a movie,' ' \'s\' to see the list of movies,' ' \'w\' to set a movie as watched,' ' \'d\' to delete a movie,' ' \'l\' to see the list of watched movies,' ' \'f\' to save or ' ' \'q\' to quit')
def menu(): name = input("Please enter your name : ") filename = "{}.txt".format(name) if file_exists(filename): with open(filename, 'r') as f: json_data = json.load(f) user = User.from_json(json_data) else: user = User(name) user_input = input( "Enter 'a' to add a movie, 's' to see the list of movies, 'w' to set a movie as watched," "'d' to delete a movie, 'l' to see list of watched movies," "or 'f' to save, and 'q' to quit") while user_input != 'q': if user_input == 'a': movie_name = user.trim_movie( input("Please enter the name of the film : ")) movie_genre = user.trim_movie( input("Please enter the genre of the film : ")) movie_year = int( input("Please enter the year the film was made : ")) user.add_movie(movie_name, movie_genre, movie_year) elif user_input == 's': for movie in user.movies: print("{}, a {} film made in {}, Watched : {}".format( movie.name, movie.genre, str(movie.year), str(movie.watched))) elif user_input == 'w': user_movie = input( "Please enter the name of the film you would like to set as watched : " ) user.set_watched(user.trim_movie(user_movie)) elif user_input == 'd': movie_name = input("Enter the name of the movie to delete : ") user.delete_movie(user.trim_movie(movie_name)) elif user_input == 'l': for movie in user.watched_movies(): print("{}, a {} film made in {}, Watched : {}".format( movie.name, movie.genre, str(movie.year), str(movie.watched))) elif user_input == 'f': with open(filename, 'w') as f: json.dump(user.json(), f) user_input = input( "Enter 'a' to add a movie, 's' to see the list of movies, 'w' to set a movie as watched," "'d' to delete a movie, 'l' to see list of watched movies," "or 'f' to save, and 'q' to quit")
def menu(): user_name = input('please enter user name: ') filename = f'{user_name}.txt' if file_exists(filename): print(f'Welcome member {user_name}') with open(filename, 'r') as usr_file: json_data = json.load(usr_file) user = User.from_json(json_data) else: user = User(user_name) print(f'Welcome {user_name}') user_input = input( "Enter 'a' to add a movie, 's' to see the list of movies, 'w' to set a movie watched, 'd' delete a movie, " "'l' to see the list of watched movies or 'f' to save and 'q' to quit " ) while user_input != 'q': if user_input == 'a': movie_name = input('enter movie name') movie_genre = input('enter movie genre') user.add_movie(movie_name, movie_genre) elif user_input == 's': for movie in user.movies: print( f'Name: {movie.name} Genre: {movie.genre} Watched: {movie.watched}' ) elif user_input == 'w': watched_movie = input('enter the movie name to set as watched') user.set_watched(watched_movie) elif user_input == 'd': delete_movie = input('enter movie name to delete: ') user.delete_movie(delete_movie) elif user_input == 'l': for movie in user.movies: print('Name: {} genre:{} worked:{}'.format( movie.name, movie.genre, movie.watched)) elif user_input == 'f': with open(filename, 'w') as f: json.dump(user.json(), f) user_input = input( "Enter 'a' to add a movie, 's' to see the list of movies, 'w' to set a movie watched, 'd' delete a movie, " "'l' to see the list of watched movies or 'q' to save and quit ")
def menu(): name = input("Enter your user name: ") filename = "{}.txt".format(name) if file_exists(filename): with open(filename, "r") as f: json_data = json.load(f) user = User.from_json(json_data) else: user = User(name) user_input = input( "Enter 'a' to add a movie, 's' to see the list of movies, 'w' to set a movie as watched, 'd' to delete a movie, 'l' to see the list of watched movies, 'f' to save, or 'q' to quit " ) while user_input != "q": if user_input == "a": movie_name = input("Enter the movie name: ") movie_genre = input("Enter the movie genre: ") user.add_movie(movie_name, movie_genre) elif user_input == "s": for movie in user.movies: print("Name: {} Genre: {} Watched {}".format( movie.name, movie.genre, movie.watched)) elif user_input == "w": movie_name = input("Enter the movie name to set as watched: ") user.set_watched(movie_name) elif user_input == "d": movie_name = input("Enter the movie name to delete: ") user.delete_movie(movie_name) elif user_input == "l": for movie in user.watched_movies(): print("Name: {} Genre: {} Watched {}".format( movie.name, movie.genre, movie.watched)) elif user_input == "f": with open(filename, "w") as f: json.dump(user.json(), f) user_input = input( "Enter 'a' to add a movie, 's' to see the list of movies, 'w' to set a movie as watched, 'd' to delete a movie, 'l' to see the list of watched movies, 'f' to save, or 'q' to quit " )
def menu(): name = input("Enter Name: ").capitalize() filename = f'{name}.txt' if file_exists(filename): with open(filename, 'r') as f: json_data = json.load(f) user = User.from_json(json_data) else: user = User(name) user_input = input( "Enter 'a' to add a movie, 'i' to see the list of movies,\n " "'w' to set movie as watched, 'd' to delete a movie, 'l' to see the list of watched movies,\n" "'s' to save or 'q' to quit: ") while user_input != 'q': if user_input == 'a': movie_name = input("Enter the movie name: ") movie_genre = input("Enter the movie genre: ") user.add_movie(movie_name, movie_genre) elif user_input == 'i': for movie in user.movies: print( f"Name: {movie.name} Genre: {movie.genre} Watched {movie.watched}" ) elif user_input == 'w': movie_name = input("Enter the movie name to set as watched: ") user.set_watched(movie_name) elif user_input == 'd': movie_name = input("Enter the movie name to delete: ") user.delete_movie(movie_name) elif user_input == 'l': for movie in user.watched_movies(): print( f"Name: {movie.name} Genre: {movie.genre} Watched {movie.watched}" ) elif user_input == 's': with open(filename, 'w') as f: json.dump(user.json(), f) user_input = input( "Enter 'a' to add a movie, 's' to see the list of movies,\n " "'w' to set movie as watched, 'd' to delete a movie,\n" "'l' to see the list of watched movies,\n" "or 'q' to save and quit: ")
def menu(): name = input('Enter your name: ') filename = "{}.txt".format(name) if file_exists(filename): with open(filename, 'r') as f: json_data = json.load(f) user = User.from_json(json_data) else: user = User(name) user_input = input( "Enter 'a' to add a movie, 's' to see the list of movies, 'w', to set a movie as watched, 'd' to delete a movie, 'l' to see the list of watched movies, or 'q' to quit: " ) while user_input != 'q': if user_input == 'a': movie_name = input("Enter the movie name: ") movie_genre = input("Enter the movie genre: ") user.add_movie(movie_name, movie_genre) elif user_input == 's': for movie in user.movies: print('Name: {} Genre: {} Watched: {}'.format( movie.name, movie.genre, movie.watched)) elif user_input == 'w': movie_name = input("Enter the movie name to set as watched") user.set_watched(movie_name) elif user_input == 'd': movie_name = input("Enter the movie name to delete") user.delete_movie(movie_name) elif user_input == 'l': for movie in user.watched_movies: print('Name: {} Genre: {} Watched: {}'.format( movie.name, movie.genre, movie.watched)) elif user_input == 'q': pass with open(filename, 'w') as f: json.dump(user.json(), f) user_input = input( "Enter 'a' to add a movie, 's' to see the list of movies, 'w', to set a movie as watched, 'd' to delete a movie, 'l' to see the list of watched movies, 'f' to save or 'q' to quit: " )
def menu(): name = input("Enter your name: ") filename = "{}.txt".format(name) if file_exists(filename): with open(filename, 'r') as f: json_data = json.load(f) user = User.from_json(json_data) else: user = User(name) user_input = input("Enter: \n\t'a' to add a movie\n" "\t's' to see the list of movies\n" "\t'w' to set a movie as watched\n" "\t'd' to delete a movie\n" "\t'l' to to see the list of watched movies\n" "\t'q' to save and quit") while user_input != 'q': if user_input == 'a': movie_name = input("Enter movie name: ") movie_genre = input("Enter movie genre: ") user.add_movie(movie_name, movie_genre) elif user_input == 's': for movie in user.movies: print("Name: {} Genre: {} Watched: {}".format(movie.name, movie.genre, movie.watched)) elif user_input == 'w': movie_name = input("Enter movie to set watched: ") user.delete_movie(movie_name) elif user_input == 'd': movie_name = input("Enter movie to delete: ") user.set_wathced(movie_name) elif user_input == 'l': for movie in user.movies: print("Name: {} Genre: {} Watched: {}".format(movie.name, movie.genre, movie.watched)) user_input = input("Enter: \n\t'a' to add a movie\n" "\t's' to see the list of movies\n" "\t'w' to set a movie as watched\n" "\t'd' to delete a movie\n" "\t'l' to to see the list of watched movies\n" "\t'q' to save and quit") with open(filename, 'w') as f: json.dump(user.json(), f)
def menu(): username = input('Enter your name: ') filename = f'{username}.txt' if file_exists(filename): with open(filename, 'r') as f: json_data = json.load(f) user = User.from_json(json_data) else: user = User(username) user_input = input("""Enter 'a' to add a movie, 's' to see the list of movies, 'w' to set a movie as watched, 'd' to delete a movie, 'l' to see the list of watched movies, 'f' to save or 'q' to quit. """) while user_input != 'q': if user_input == 'a': movie_name = input('Enter the movie name: ') movie_genre = input('Enter the movie genre: ') user.add_movie(movie_name, movie_genre) elif user_input == 's': for movie in user.movies: print(f'Name: {movie.name}, Genre: {movie.genre}, Watched: {movie.watched}') elif user_input == 'w': movie_name = input('Enter the movie name to set as watched: ') user.set_watched(movie_name) elif user_input == 'd': movie_name = input('Enter the movie name to delete: ') user.delete_movie(movie_name) elif user_input == 'l': for movie in user.watched_movies(): print(f'Name: {movie.name}, Genre: {movie.genre}, Watched: {movie.watched}') elif user_input == 'f': with open(filename, 'w') as f: json.dump(user.json(), f) user_input = input("""Enter 'a' to add a movie, 's' to see the list of movies, 'w' to set a movie as watched, 'd' to delete a movie, 'l' to see the list of watched movies, 'f' to save or 'q' to quit. """)
def menu(): name = input('Enter your name: ') filename = '{}.txt'.format(name) if file_exists(filename): with open(filename, 'r') as f: json_data = json.load(f) user = User.read_from_json(json_data) else: user = User(name) selection = input(selection_text) while selection != 'q': if selection == 'a': movie_name = input("Enter the movie name: ") movie_genre = input("Enter the movie genre: ") user.add_movie(movie_name, movie_genre) elif selection == 's': for movie in user.movies: print("Name: {} Genre: {} Watched: {}.".format( movie.name, movie.genre, movie.watched)) elif selection == 'w': movie_name = input("Enter the movie name to be set as watched ") user.watch_movie(movie_name) elif selection == 'd': movie_name = input("Enter the movie name to delete ") user.delete_movie(movie_name) elif selection == 'l': for movie in user.get_watched_movies(): print("Name: {} Genre: {} Watched: {}.".format( movie.name, movie.genre, movie.watched)) selection = input(selection_text) with open(filename, 'w') as f: json.dump(user.json(), f)
from user import User import json user = User("Dave") user.add_movie("The Martian", "Sci-fi") user.add_movie("Star Trek Beyond", "Action") print(user.json()) with open('my_file.txt', 'w') as f: json.dump(user.json(), f)
from user import User import json import os user = User("Craig") user.add_movie("Black Panther", "Sci-Fi", 2018) user.add_movie("Jumanji", "Comedy", 2018) user.add_movie("I, Tonya", "Dramedy", 2017) print(user.trim_movie("Black Panther ")) print(user.trim_movie(" Titanic")) # with open('my_file.txt', 'w') as f: # json.dump(user.json(), f) # # with open('my_file.txt', 'r') as f: # json_data = json.load(f) # user = User.from_json(json_data) # print(user.json()) # # foo = [2, 18, 9, 22, 17, 24, 8, 12, 27] # foo_3 = list(filter(lambda x: x % 3 == 0, foo)) # #print(foo_3) def menu(): name = input("Please enter your name : ") filename = "{}.txt".format(name) if file_exists(filename): with open(filename, 'r') as f: json_data = json.load(f) user = User.from_json(json_data) else:
from user import User import json user = User("Joe") user.add_movie("The Matrix", "Sci-Fi") user.add_movie("The Interview", "Comedy") with open("my_file.txt", 'r') as f: json_data = json.load(f) user = User.from_json(json_data) print(user.json())
def Menu(): #ask for the user's name # check if a file exixts for the entered user # if it exists then load the data # give a list of option such as: # add a movie # see list of movies: # set the movie as watched # delete a movie by name # see list of watched movies # save and quit name = input("Enter user name: ") filename = "{}.txt".format(name) if file_exists(filename): with open(filename, 'r') as file: json_data = json.load(file) user = User.load_from_json(json_data) else: user = User(name) user_input = input( "Enter 'a' to add a movie, 's' to see the list of movies," "'w' to set a movie as watched,'d' to delete a movie,'l' to see a lst of watched movie, 'save' to save data, 'q' to quit" ) while user_input != 'q': if user_input == 'a': movie_name = input("enter movie name: ") movie_genre = input("enter movie genre: ") user.add_movie(movie_name, movie_genre) elif user_input == 's': for movie in user.movies: print("Name {} Genre {} Watched {}".format( movie.name, movie.genre, movie.watched)) elif user_input == 'w': set_movie_watched = input( " enter the movie name to be set as watched: ") user.set_watched(set_movie_watched) elif user_input == 'd': delete_movie = input("enter movie name to be deleted: ") user.delete_movie(delete_movie) elif user_input == 'l': for movie in user.movies_watched(): print("Name {} Genre {} Watched {}".format( movie.name, movie.genre, movie.watched)) elif user_input == 'save': with open(filename, 'w') as f: json.dump(user.json(), f) user_input = input( "Enter 'a' to add a movie, 's' to see the list of movies," "'w' to set a movie as watched", "'d' to delete a movie", "'l' to see a lst of watched movie", "'save' to save data", "'q' to quit")
from user import User import json user = User('Steve') user.add_movie('The Matrix', 'sci-fi') user.add_movie('The Interview', 'comedy') FILE_NAME = 'my_file.txt' with open(FILE_NAME, 'w') as f: json.dump(user.json, f, indent=4) with open('my_file.txt', 'r') as f: json_data = json.load(f) user = User.from_json(json_data) print(json.dumps(user.json, indent=4))
from user import User from movie import Movie user = User("Nikos") user.add_movie("Matrix", "Sci-Fi") user.add_movie("The dictator", "Comedy") # Ideally, the following will create a file with the user name and the respective movies #user.save_to_file() user.load_from_file()
def menu(): # Ask for the user's name name = input("Enter your name: ") # Check if a file exists for that user # If it already exists, welcome then and load their data. # If not, create a User object filename = "{}.json".format(name) if file_exists(filename): with open(filename, 'r') as f: try: json_data = json.load(f) except json.decoder.JSONDecodeError: print("Invalid JSON file") return user = User.from_json(json_data) else: user = User(name) user_input = input('''Enter: 'a' to add a movie, 'm' to see the list of movies, 'w' to set a movie as watched, 'd' to delete a movie, 'l' to see a list of watched movies, 's' to save, 'q' to quit ''') while user_input != 'q': if user_input == 'a': movie_name = input("Enter the movie name: ") movie_genre = input("Enter the genre: ") user.add_movie(movie_name, movie_genre) elif user_input == 'm': for movie in user.movies: print( "Name: {name}, Genre: {genre}, Watched: {watched}".format( **movie.json())) # This is cool!!! elif user_input == 'w': movie_name = input("Enter the movie name to set as watched: ") user.set_watched(movie_name) elif user_input == 'd': movie_name = input("Enter the movie name to delete: ") user.delete_movie(movie_name) elif user_input == 'l': for movie in user.watched_movies(): print( "Name: {name}, Genre: {genre}, Watched: {watched}".format( **movie.json())) # This is cool!!! elif user_input == 's': with open(filename, 'w') as f: json.dump(user.json(), f) elif user_input == 'q': return else: print("That is not a valid choice") user_input = input('''Enter: 'a' to add a movie, 'm' to see the list of movies, 'w' to set a movie as watched, 'd' to delete a movie, 'l' to see a list of watched movies, 's' to save, 'q' to quit ''')
user_name = input("->Enter your name: ") user = User(user_name) choice = 9 while choice != 0: choice = int( input("_______________________________________________________" "\nEnter 1 to add a movie." "\nEnter 2 to delete a movie." "\nEnter 3 to change the movie status(Watched)." "\nEnter 4 to show the list of watched movies." "\nEnter 5 to save the file." "\nEnter 6 to view the file." "\n_______________________________________________________\n")) if choice == 1: user.add_movie() elif choice == 2: target = input("Enter the name of the movie to be deleted: ") user.delete_movie(target) elif choice == 3: target = input("Enter the name of the movie: ") user.movie_status(target) elif choice == 4: user.watched_movies() elif choice == 5: user.save_to_file() elif choice == 6: user.view_saved_file() elif choice == 0: exit()