Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def save_dict_to_file(dic):
- f = open('dict.txt', 'w')
- f.write(str(dic))
- f.close()
- def load_dict_from_file():
- f = open('dict.txt', 'r')
- data = f.read()
- f.close()
- return eval(data)
- def open_or_loading():
- print('nnHello to Movies.basenn'
- 'Do you want to load an existent database or create a new one?nn'
- 'Choose 1 for loading an existent.n'
- 'Choose 2 for create a new database.n')
- user_answer = input('Option: ')
- if user_answer == '1':
- database = load_dict_from_file()
- elif user_answer == '2':
- database = {}
- save_dict_to_file(database)
- else:
- print('Wrong option, try again.n')
- open_or_loading()
- def view_all_list():
- for key, value in database.items():
- print(key, value)
- def add_movie():
- last_inserted = (len(database))
- movie_name = input('What is the name of the movie: ')
- def year_movie():
- try:
- movie_year = int(input('Released in year: '))
- except:
- print('You must insert a year format: e.g.: 2018')
- year_movie()
- else:
- if movie_year < 1000 or movie_year > 9999:
- print('You must insert a year format: e.g.: 2018')
- year_movie()
- else:
- return movie_year
- movie_year = year_movie()
- movie_director = input('Directed by: ')
- def category_movie():
- print('Choose one category:nn'
- '1 - Actionn'
- '2 - Adventuren'
- '3 - Avant-garde / Experimentaln'
- '4 - Comedyn'
- '5 - Comedy-Draman'
- '6 - Crimen'
- '7 - Draman'
- '8 - Epicn'
- '9 - Family-Childrenn'
- '10 - Fantasyn'
- '11 - Historical-Filmn'
- '12 - Horrorn'
- '13 - Musicaln'
- '14 - Mysteryn'
- '15 - Romancen'
- '16 - Sci-Fi / Science-Fictionn'
- '17 - Spy Filmn'
- '18 - Thrillern'
- '19 - Warn'
- '20 - Westernn'
- '21 - Adultn')
- category = int(input('Category: '))
- def switch_demo(argument):
- switcher = {
- 1: 'Action',
- 2: 'Adventure',
- 3: 'Avant-garde / Experimental',
- 4: 'Comedy',
- 5: 'Comedy-Drama',
- 6: 'Crime',
- 7: 'Drama',
- 8: 'Epic',
- 9: 'Family-Children',
- 10: 'Fantasy',
- 11: 'Historical-Film',
- 12: 'Horror',
- 13: 'Musical',
- 14: 'Mystery',
- 15: 'Romance',
- 16: 'Sci-Fi / Science-Fiction',
- 17: 'Spy Film',
- 18: 'Thriller',
- 19: 'War',
- 20: 'Western',
- 21: 'Adult'
- }
- return switcher.get(category)
- if category < 1 or category > 21:
- print('nInvalid Categoryn')
- category_movie()
- switch_demo(category)
- else:
- return switch_demo(category)
- movie_category = category_movie()
- database[last_inserted + 1] = {}
- database[last_inserted + 1]['Movie Name'] = movie_name.upper()
- database[last_inserted + 1]['Movie Year'] = movie_year
- database[last_inserted + 1]['Director Name'] = movie_director.upper()
- database[last_inserted + 1]['Movie Category'] = movie_category
- save_dict_to_file(database)
- print(f'nMovie {movie_name} added to databasen')
- menu_initial()
- def menu_initial():
- print('nnChose one option:nn'
- 'Select 1 to view the movies list.n'
- 'Select 2 to add a new movie.n'
- 'Select 3 to find a movie.n'
- 'Select 4 to delete a movie.n'
- 'Select 5 to exit outn')
- user_selection = (input('Option: '))
- if user_selection == '1':
- view_all_list()
- menu_initial()
- elif user_selection == '2':
- add_movie()
- menu_initial()
- elif user_selection == '3':
- print('Finding')
- menu_initial()
- elif user_selection == '4':
- print('deleting')
- menu_initial()
- elif user_selection == '5':
- print('Thanks for using Movie.Base. Bye-bye!')
- exit()
- else:
- print('Option do not exist')
- menu_initial()
- menu_initial()
- open_or_loading()
- def year_movie():
- try:
- movie_year = int(input('Released in year: '))
- except:
- print('You must insert a year format: e.g.: 2018')
- return year_movie() ## return from recursive call
- else:
- if movie_year < 1000 or movie_year > 9999:
- print('You must insert a year format: e.g.: 2018')
- return year_movie() ## return from recursive call
- else:
- return movie_year
Add Comment
Please, Sign In to add comment