Guest User

Untitled

a guest
Nov 19th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.28 KB | None | 0 0
  1. def save_dict_to_file(dic):
  2. f = open('dict.txt', 'w')
  3. f.write(str(dic))
  4. f.close()
  5.  
  6.  
  7. def load_dict_from_file():
  8. f = open('dict.txt', 'r')
  9. data = f.read()
  10. f.close()
  11. return eval(data)
  12.  
  13.  
  14. def open_or_loading():
  15.  
  16. print('nnHello to Movies.basenn'
  17. 'Do you want to load an existent database or create a new one?nn'
  18. 'Choose 1 for loading an existent.n'
  19. 'Choose 2 for create a new database.n')
  20. user_answer = input('Option: ')
  21.  
  22. if user_answer == '1':
  23. database = load_dict_from_file()
  24.  
  25. elif user_answer == '2':
  26. database = {}
  27. save_dict_to_file(database)
  28. else:
  29. print('Wrong option, try again.n')
  30. open_or_loading()
  31.  
  32.  
  33. def view_all_list():
  34. for key, value in database.items():
  35. print(key, value)
  36.  
  37.  
  38.  
  39. def add_movie():
  40.  
  41. last_inserted = (len(database))
  42. movie_name = input('What is the name of the movie: ')
  43.  
  44. def year_movie():
  45. try:
  46. movie_year = int(input('Released in year: '))
  47. except:
  48. print('You must insert a year format: e.g.: 2018')
  49. year_movie()
  50. else:
  51. if movie_year < 1000 or movie_year > 9999:
  52. print('You must insert a year format: e.g.: 2018')
  53. year_movie()
  54. else:
  55. return movie_year
  56. movie_year = year_movie()
  57. movie_director = input('Directed by: ')
  58.  
  59. def category_movie():
  60.  
  61. print('Choose one category:nn'
  62. '1 - Actionn'
  63. '2 - Adventuren'
  64. '3 - Avant-garde / Experimentaln'
  65. '4 - Comedyn'
  66. '5 - Comedy-Draman'
  67. '6 - Crimen'
  68. '7 - Draman'
  69. '8 - Epicn'
  70. '9 - Family-Childrenn'
  71. '10 - Fantasyn'
  72. '11 - Historical-Filmn'
  73. '12 - Horrorn'
  74. '13 - Musicaln'
  75. '14 - Mysteryn'
  76. '15 - Romancen'
  77. '16 - Sci-Fi / Science-Fictionn'
  78. '17 - Spy Filmn'
  79. '18 - Thrillern'
  80. '19 - Warn'
  81. '20 - Westernn'
  82. '21 - Adultn')
  83.  
  84. category = int(input('Category: '))
  85.  
  86. def switch_demo(argument):
  87. switcher = {
  88. 1: 'Action',
  89. 2: 'Adventure',
  90. 3: 'Avant-garde / Experimental',
  91. 4: 'Comedy',
  92. 5: 'Comedy-Drama',
  93. 6: 'Crime',
  94. 7: 'Drama',
  95. 8: 'Epic',
  96. 9: 'Family-Children',
  97. 10: 'Fantasy',
  98. 11: 'Historical-Film',
  99. 12: 'Horror',
  100. 13: 'Musical',
  101. 14: 'Mystery',
  102. 15: 'Romance',
  103. 16: 'Sci-Fi / Science-Fiction',
  104. 17: 'Spy Film',
  105. 18: 'Thriller',
  106. 19: 'War',
  107. 20: 'Western',
  108. 21: 'Adult'
  109. }
  110. return switcher.get(category)
  111.  
  112. if category < 1 or category > 21:
  113. print('nInvalid Categoryn')
  114. category_movie()
  115. switch_demo(category)
  116.  
  117. else:
  118. return switch_demo(category)
  119.  
  120. movie_category = category_movie()
  121.  
  122. database[last_inserted + 1] = {}
  123. database[last_inserted + 1]['Movie Name'] = movie_name.upper()
  124. database[last_inserted + 1]['Movie Year'] = movie_year
  125. database[last_inserted + 1]['Director Name'] = movie_director.upper()
  126. database[last_inserted + 1]['Movie Category'] = movie_category
  127.  
  128. save_dict_to_file(database)
  129.  
  130. print(f'nMovie {movie_name} added to databasen')
  131.  
  132. menu_initial()
  133.  
  134.  
  135. def menu_initial():
  136. print('nnChose one option:nn'
  137. 'Select 1 to view the movies list.n'
  138. 'Select 2 to add a new movie.n'
  139. 'Select 3 to find a movie.n'
  140. 'Select 4 to delete a movie.n'
  141. 'Select 5 to exit outn')
  142. user_selection = (input('Option: '))
  143.  
  144. if user_selection == '1':
  145. view_all_list()
  146. menu_initial()
  147. elif user_selection == '2':
  148. add_movie()
  149. menu_initial()
  150. elif user_selection == '3':
  151. print('Finding')
  152. menu_initial()
  153. elif user_selection == '4':
  154. print('deleting')
  155. menu_initial()
  156. elif user_selection == '5':
  157. print('Thanks for using Movie.Base. Bye-bye!')
  158. exit()
  159. else:
  160. print('Option do not exist')
  161. menu_initial()
  162.  
  163. menu_initial()
  164.  
  165. open_or_loading()
  166.  
  167. def year_movie():
  168. try:
  169. movie_year = int(input('Released in year: '))
  170. except:
  171. print('You must insert a year format: e.g.: 2018')
  172. return year_movie() ## return from recursive call
  173. else:
  174. if movie_year < 1000 or movie_year > 9999:
  175. print('You must insert a year format: e.g.: 2018')
  176. return year_movie() ## return from recursive call
  177. else:
  178. return movie_year
Add Comment
Please, Sign In to add comment