Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- In SuperCigarette company questionaries are collected everyday by hostesses.
- By end of each day secretary inserts values into system.
- Each record is name, email and age of a user.
- // change age to birthdate, to be precise
- There is a need to automate:
- - creating unique usernames (just for the list provided below, no database of course!)
- - creating dedicated string message for under age user
- - validate email
- - validate age
- - prepare dedicated message for under age user
- - proper exceptions handling is nice thing to have
- Our programmer had time just to do some of the work.
- Please finish what he started so main() function gives us what is described above
- """
- import random
- import datetime
- # the code needs to have the below library installed to work, it's already avaliable
- # and can be downloaded by:
- # sudo pip install --upgrade pip
- # sudo pip install validate_email
- #
- # found on: https://github.com/syrusakbary/validate_email
- from validate_email import validate_email
- now = datetime.datetime.now()
- current_Year = now.year
- list_of_users = [
- ['Pawel', 'pawel@gmail.com', '1956'],
- ['Piotr', 'piottre@gmail.com', '1958'],
- ['Marlena', 'marle92@yahoo.com', '1992'],
- ['Eustachy', 'eustaa@wp.pl', '1977'],
- ['Krystyna', 'cristina2001@gmail.com', '2001'],
- ['Zenon', 'zenon@pl', '1997'],
- ['Adam', 'adam.szalonygmail.com', '1998'],
- ['Janusz', 'janusz.biznesu@onet.pl', '1999'],
- ['Bartosz', 'bart79@gmail.com', '1979'],
- ['Hanna', 'hanna.nowak@wp.pl', '1988'],
- ['Marzena', 'marzenia91@interia.pl', '1991'],
- ['Karol', 'karol96kowalski@gmail.com', '1996'],
- ['Julia', 'goracajula@wp.pl', '1983'],
- ['Patryk', 'pattry@gmail.com', '2019'],
- ['Karolina', 'karolina.malenczuk@wp.pl', '2006'],
- ['Rafał', 'rafal.karol@interia.pl', '2002'],
- ['Fryderyk', 'fryderyk.chopin66@gmail.com', '1966'],
- ['Georgina', 'georgia99@gmail.com', '1999'],
- ['Jolanta', 'jola.por87@wp.pl', '1987'],
- ['Karolina Maria', 'karola.maria.kwiatkowska.gmail.com', '1994'],
- ['Piotr', 'piotr58starachowski@gmail.com', '1958'],
- ['Piotr', 'piotr.konieczny@wp.pl', '1999'],
- ['Zenon', '123zenek@gmail.com', '1999'],
- ['Karolina', 'karolina666@gmail.com', '2000']
- ]
- list_of_full_rights_users = []
- list_of_underage_users = []
- """
- for user in list_of_users:
- username = user
- is_valid = validate_email(user[1])
- print(is_valid)
- for user in list_of_users:
- username = user
- if (int(user[2]) < current_Year):
- user.append("bDate_ok")
- else:
- user.append("wrong_bDate") // for dates entered totally wrong, like 2019 that make no sense
- for user in list_of_users:
- username = user
- print(user)
- """
- def validate_age(age: int) -> bool:
- if ((age - current_Year) > 17):
- print (age)
- return True
- else:
- return False
- print(list_of_users[6][1])
- is_email_valid = validate_email(list_of_users[6][1])
- # print(current_Year - (int(list_of_users[6][2])))
- print(is_email_valid)
- print(int(list_of_users[6][2]))
- is_age_valid = validate_age(int(list_of_users[6][2]))
- print(is_age_valid)
- # for user in list_of_users:
- # if validate_email(user[1]):
- # if validate_age(user[2]):
- # list_of_full_rights_users.append(user)
- print("list_of_full_rights_users: ", list_of_full_rights_users)
- def create_list_of_full_rights_users(list_with_users_info: list) -> list:
- for user in list_with_users_info:
- if validate_email(user[1]):
- if validate_age(user[2]):
- list_of_full_rights_users.append(user)
- print(list_of_full_rights_users)
- return list_of_full_rights_users
- def create_list_of_underage_users(list_with_users_info: list) -> list:
- for user in list_with_users_info:
- if validate_email(user[1]):
- if validate_age(user[2]) == False:
- list_of_underage_users.append(user)
- print(list_of_underage_users)
- return list_of_underage_users
- def prepare_data(list_with_users_info):
- """
- Method should return list of users that are fully priviliged and list of underage users if their data //
- (email, age) is valid
- """
- full_rights_users = create_list_of_full_rights_users(list_with_users_info)
- underage_users = create_list_of_underage_users(list_with_users_info)
- return full_rights_users, underage_users
- def create_usernames_list(list_with_users_info: list) -> list:
- """
- Function adds new username to a list if all fields from questionarie are valid
- param: list_with_users_info, list with user relevanat information
- return: list with new unique usernames
- """
- for user in list_with_users_info:
- print(user)
- pass
- # def validate_email(email: str) -> bool:
- # """
- # param: email, string with email
- # return: True if email is valid, False if invalid
- # obsolete since an external module is used
- # """
- # return True
- def create_message_for_underage_user(user: str, age: int) -> str:
- """
- param: user, string users name
- param: age, int with age of a user
- return: string message with unique value for specific user
- """
- message = "Dear USER, your age AGE is less then 18, which is needed for purchasing nicotine products. \
- You can still join our community but with limited rights for purchase."
- def main():
- full_rights_users, underage_users = prepare_data(list_of_users)
- print(" main()__list_of_full_rights_users: ", list_of_full_rights_users)
- print(list_of_full_rights_users)
- print(list_of_underage_users)
- usernames_catA = create_usernames_list(full_rights_users)
- usernames_catB = create_usernames_list(underage_users)
- print("All users that are fully privilieged: ", usernames_catA)
- print("All users that are underage: ", usernames_catB)
- for under_age_user in underage_users:
- print("Sending message to email {}".format(email))
- print("Message body:\n", create_message_for_underage_user(user, age))
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement