Advertisement
Guest User

pypy

a guest
May 4th, 2018
808
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.57 KB | None | 0 0
  1. """
  2. In SuperCigarette company questionaries are collected everyday by hostesses.
  3. By end of each day secretary inserts values into system.
  4. Each record is name, email and age of a user.
  5.  
  6. // change age to birthdate, to be precise
  7.  
  8. There is a need to automate:
  9. - creating unique usernames (just for the list provided below, no database of course!)
  10. - creating dedicated string message for under age user
  11. - validate email
  12. - validate age
  13. - prepare dedicated message for under age user
  14. - proper exceptions handling is nice thing to have
  15. Our programmer had time just to do some of the work.
  16. Please finish what he started so main() function gives us what is described above
  17. """
  18.  
  19.  
  20. import random
  21. import datetime
  22.  
  23. # the code needs to have the below library installed to work, it's already avaliable
  24. # and can be downloaded by:
  25. # sudo pip install --upgrade pip
  26. # sudo pip install validate_email
  27. #
  28. # found on: https://github.com/syrusakbary/validate_email
  29.  
  30. from validate_email import validate_email
  31.  
  32. now = datetime.datetime.now()
  33. current_Year = now.year
  34.  
  35.  
  36. list_of_users = [
  37. ['Pawel', 'pawel@gmail.com', '1956'],
  38. ['Piotr', 'piottre@gmail.com', '1958'],
  39. ['Marlena', 'marle92@yahoo.com', '1992'],
  40. ['Eustachy', 'eustaa@wp.pl', '1977'],
  41. ['Krystyna', 'cristina2001@gmail.com', '2001'],
  42. ['Zenon', 'zenon@pl', '1997'],
  43. ['Adam', 'adam.szalonygmail.com', '1998'],
  44. ['Janusz', 'janusz.biznesu@onet.pl', '1999'],
  45. ['Bartosz', 'bart79@gmail.com', '1979'],
  46. ['Hanna', 'hanna.nowak@wp.pl', '1988'],
  47. ['Marzena', 'marzenia91@interia.pl', '1991'],
  48. ['Karol', 'karol96kowalski@gmail.com', '1996'],
  49. ['Julia', 'goracajula@wp.pl', '1983'],
  50. ['Patryk', 'pattry@gmail.com', '2019'],
  51. ['Karolina', 'karolina.malenczuk@wp.pl', '2006'],
  52. ['Rafał', 'rafal.karol@interia.pl', '2002'],
  53. ['Fryderyk', 'fryderyk.chopin66@gmail.com', '1966'],
  54. ['Georgina', 'georgia99@gmail.com', '1999'],
  55. ['Jolanta', 'jola.por87@wp.pl', '1987'],
  56. ['Karolina Maria', 'karola.maria.kwiatkowska.gmail.com', '1994'],
  57. ['Piotr', 'piotr58starachowski@gmail.com', '1958'],
  58. ['Piotr', 'piotr.konieczny@wp.pl', '1999'],
  59. ['Zenon', '123zenek@gmail.com', '1999'],
  60. ['Karolina', 'karolina666@gmail.com', '2000']
  61. ]
  62.  
  63.  
  64.  
  65.  
  66.  
  67. list_of_full_rights_users = []
  68. list_of_underage_users = []
  69.  
  70.  
  71. """
  72. for user in list_of_users:
  73. username = user
  74. is_valid = validate_email(user[1])
  75. print(is_valid)
  76.  
  77.  
  78. for user in list_of_users:
  79. username = user
  80. if (int(user[2]) < current_Year):
  81. user.append("bDate_ok")
  82. else:
  83. user.append("wrong_bDate") // for dates entered totally wrong, like 2019 that make no sense
  84.  
  85. for user in list_of_users:
  86. username = user
  87. print(user)
  88. """
  89.  
  90. def validate_age(age: int) -> bool:
  91. if ((age - current_Year) > 17):
  92. print (age)
  93. return True
  94. else:
  95. return False
  96.  
  97. print(list_of_users[6][1])
  98.  
  99. is_email_valid = validate_email(list_of_users[6][1])
  100. # print(current_Year - (int(list_of_users[6][2])))
  101. print(is_email_valid)
  102. print(int(list_of_users[6][2]))
  103. is_age_valid = validate_age(int(list_of_users[6][2]))
  104. print(is_age_valid)
  105.  
  106. # for user in list_of_users:
  107. # if validate_email(user[1]):
  108. # if validate_age(user[2]):
  109. # list_of_full_rights_users.append(user)
  110.  
  111. print("list_of_full_rights_users: ", list_of_full_rights_users)
  112.  
  113. def create_list_of_full_rights_users(list_with_users_info: list) -> list:
  114.  
  115. for user in list_with_users_info:
  116. if validate_email(user[1]):
  117. if validate_age(user[2]):
  118. list_of_full_rights_users.append(user)
  119. print(list_of_full_rights_users)
  120. return list_of_full_rights_users
  121.  
  122. def create_list_of_underage_users(list_with_users_info: list) -> list:
  123. for user in list_with_users_info:
  124. if validate_email(user[1]):
  125. if validate_age(user[2]) == False:
  126. list_of_underage_users.append(user)
  127. print(list_of_underage_users)
  128. return list_of_underage_users
  129.  
  130.  
  131. def prepare_data(list_with_users_info):
  132. """
  133. Method should return list of users that are fully priviliged and list of underage users if their data //
  134. (email, age) is valid
  135. """
  136. full_rights_users = create_list_of_full_rights_users(list_with_users_info)
  137. underage_users = create_list_of_underage_users(list_with_users_info)
  138. return full_rights_users, underage_users
  139.  
  140. def create_usernames_list(list_with_users_info: list) -> list:
  141. """
  142. Function adds new username to a list if all fields from questionarie are valid
  143. param: list_with_users_info, list with user relevanat information
  144. return: list with new unique usernames
  145. """
  146. for user in list_with_users_info:
  147. print(user)
  148. pass
  149.  
  150.  
  151. # def validate_email(email: str) -> bool:
  152. # """
  153. # param: email, string with email
  154. # return: True if email is valid, False if invalid
  155. # obsolete since an external module is used
  156. # """
  157.  
  158. # return True
  159.  
  160.  
  161.  
  162.  
  163. def create_message_for_underage_user(user: str, age: int) -> str:
  164.  
  165. """
  166. param: user, string users name
  167. param: age, int with age of a user
  168. return: string message with unique value for specific user
  169. """
  170. message = "Dear USER, your age AGE is less then 18, which is needed for purchasing nicotine products. \
  171. You can still join our community but with limited rights for purchase."
  172. def main():
  173. full_rights_users, underage_users = prepare_data(list_of_users)
  174. print(" main()__list_of_full_rights_users: ", list_of_full_rights_users)
  175. print(list_of_full_rights_users)
  176. print(list_of_underage_users)
  177. usernames_catA = create_usernames_list(full_rights_users)
  178. usernames_catB = create_usernames_list(underage_users)
  179. print("All users that are fully privilieged: ", usernames_catA)
  180. print("All users that are underage: ", usernames_catB)
  181. for under_age_user in underage_users:
  182. print("Sending message to email {}".format(email))
  183. print("Message body:\n", create_message_for_underage_user(user, age))
  184.  
  185. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement