示例#1
0
def main():
    raw_contacts_list = get_contacts('phonebook_raw.csv')

    my_phone_book = PhoneBook()
    for raw_contact in raw_contacts_list:
        contact = Contact(raw_contact[:7])
        my_phone_book.add_contact(contact)

    contacts_list = my_phone_book.get_contacts_list()
    write_contacts('phonebook.csv', contacts_list)
示例#2
0
def main():
    phone_book = PhoneBook(load_book())

    while True:
        print('--- Phone Book ----')
        print('1.Add a new contact.\n'
              '2.Search a contact.\n'
              '3.Display Contacts.\n'
              '4.Exit\n')

        option = input("Enter option: ")
        if option == '1':
            name = input("Name: ")
            phone = input("Phone: ")
            contact = {'name': name, 'phone': phone}
            phone_book.add_contact(contact)
        elif option == '2':
            name = input("Enter name: ")
            print(phone_book.get_contact(name))
        elif option == '3':
            phone_book.print_contacts()
        elif option == '4':
            save_book(phone_book.get_contacts())
            print('Exiting program...')
            break
示例#3
0
                   'Smith',
                   '+71234567809',
                   telegram='@jhony',
                   email='*****@*****.**')
    glen = Contact('Glen',
                   'Mayer',
                   '+73454364644',
                   address='Не дом и не улица')
    bill = Contact('Bill',
                   'Murrey',
                   '+73216547809',
                   is_favorite=True,
                   telegram='@billyyyy',
                   skype='*****@*****.**')

    my_book = PhoneBook('Черный список людей, которым я не собираюсь звонить')
    my_book.show_all()

    my_book.add(jhon)
    my_book.add(glen)
    my_book.show_all()

    my_book.show_favorite()
    my_book.add(bill)
    my_book.show_favorite()

    my_buddy = my_book.get_contact('Мой старый приятель',
                                   'Забыл, блин, как его там')
    print(my_buddy)  # None
    my_enemy = my_book.get_contact('Bill', 'Murrey')
    print(my_enemy)
示例#4
0
    if args.debug:
        print(mms_headers)
        print(mms_data)

    # Did we get a successful message or an error?
    if mms_headers['Content-Type'] == 'text/plain':
        # MMS message contains an error message
        print('MMS Error:', mms_data[0]['data'])
    elif mms_headers['Content-Type'].startswith(
            'application/vnd.wap.multipart'):
        # Print out some of the more important headers

        # Look up names in our phonebook
        if (args.phonebook and os.path.isfile('phonebook.db')):
            phonebook = PhoneBook()

            from_name = phonebook.get_name(mms_headers['From'])
            print(
                "From:\n\t", ' '.join(from_name)
                if from_name is not None else mms_headers['From'])

            to_names = phonebook.get_names(mms_headers['To'])
            to_names = [
                ' '.join(to_names[to]).rstrip(' ') if to in to_names else to
                for to in mms_headers['To']
            ]
            print("To:\n\t", to_names)
        else:
            print("From:\n\t", mms_headers['From'])
            print("To:\n\t", mms_headers['To'])
示例#5
0
#
# print('Enter the numerator')
# numerator = input()
#
# print('Enter the denominator')
# denominator = input()
#
# fraction = Fraction(float(numerator), float(denominator))
#
# print('Sum = {numbers_sum}'.format(numbers_sum=fraction.numbers_sum()))
# print('Division = {numbers_division}'.format(numbers_division=fraction.numbers_division()))
# print('Multiplication = {numbers_multiplication}'.format(numbers_multiplication=fraction.numbers_multiplication()))
# print('Subtraction = {numbers_subtraction}'.format(numbers_subtraction=fraction.numbers_subtraction()))

# See PyCharm help at https://www.jetbrains.com/help/pycharm/
if __name__ == '__main__':

    # --------PhoneBook Task--------
    phoneBook = PhoneBook()
    phoneBook.setAllData()
    phoneBook.getAllData()
    # # --------PhoneBook JsonTask--------
    phoneBook.exportData()
    #
    del phoneBook

    # --------User Task----------
    student = Student()
    student.setAllData()
    student.getAllData()
示例#6
0
 def __init__(self) -> None:
     self.__isRunning = True
     self.__phoneBook = PhoneBook(CsvContactModel())
示例#7
0
class PhoneBookScreen:
    def __init__(self) -> None:
        self.__isRunning = True
        self.__phoneBook = PhoneBook(CsvContactModel())

    def showMainMenu(self) -> None:
        while self.__isRunning == True:
            print("Select one option below:")
            print("\t1. Add contact")
            print("\t2. Show all contacts")
            print("\t3. Update contact")
            print("\t4. Delete contact")
            print("\t5. Quit")

            key = input()
            if key == "1":
                self.__showAddContactScreen()
            elif key == "2":
                self.__showAllContactsScreen()
            elif key == "3":
                self.__showUpdateContactsScreen()
            elif key == "4":
                self.__showDeleteContactScreen()
            elif key == "5":
                self.__quit()
            else:
                print("Invalid input, please enter again!")

    def __showAllContactsScreen(self) -> None:
        try:
            allContacts: List[Contact] = self.__phoneBook.getAllContacts()
        except DatabaseError:
            print("Cannot connect to Database")
            return

        #if no exeption occurs, print all contact
        print("All contacts:", "\n")
        for index in range(len(allContacts)):
            print(f"Contact {index + 1}:")
            print(f"\tName: {allContacts[index].name()}")
            print(f"\tPhone number: {allContacts[index].phoneNumber()}")
            print("")

    def __showAddContactScreen(self) -> None:
        while True:
            print("Enter name: ", end="")
            name: str = input()
            if self.__phoneBook.isContactExist(name) == True:
                print("This user already exist, please enter the other name!")
            else:
                break

        print("Enter phone number: ", end="")
        phoneNumber: str = input()
        newContact: Contact = Contact(name, phoneNumber)
        self.__phoneBook.addContact(newContact)
        return None

    def __showUpdateContactsScreen(self) -> None:
        print("Please enter user need to be updated: ", end="")
        name = input()
        if self.__phoneBook.isContactExist(name) == False:
            print("There is no contact with that name")
        else:
            print("New phone number: ")
            phoneNumber: str = input()
            self.__phoneBook.updateContact(Contact(name, phoneNumber))

    def __showDeleteContactScreen(self) -> None:
        print("Please enter user need to be deleted: ", end="")
        name = input()
        if self.__phoneBook.isContactExist(name) == False:
            print("There is no contact with that name")
        else:
            self.__phoneBook.deleteContact(name)

    def __quit(self) -> None:
        self.__isRunning = False
        return None
示例#8
0
 def setUp(self) -> None:
     self.phonebook = PhoneBook()
示例#9
0
class PhoneBookTest(unittest.TestCase):
    def setUp(self) -> None:
        self.phonebook = PhoneBook()

    def tearDown(self) -> None:
        pass

    def test_lookup_by_name(self):
        self.phonebook.add("Bob", "12345")
        number = self.phonebook.lookup("Bob")
        self.assertEqual("12345", number)

    def test_missing_name(self):
        with self.assertRaises(KeyError):
            self.phonebook.lookup("missing")

    # @unittest.skip("WIP")
    def test_empty_phonebook_is_consistent(self):
        self.assertTrue(self.phonebook.is_consistent())

    def test_is_consistent_with_different_entries(self):
        self.phonebook.add("Bob", "12345")
        self.phonebook.add("Anna", "98765")
        self.assertTrue(self.phonebook.is_consistent())

    def test_inconsistent_with_duplicate_entries(self):
        self.phonebook.add("Bob", "12345")
        self.phonebook.add("Sue", "12345")
        self.assertFalse(self.phonebook.is_consistent())

    def test_inconsistent_with_duplicate_prefix(self):
        self.phonebook.add("Bob", "12345")
        self.phonebook.add("Sue", "123")
        self.assertFalse(self.phonebook.is_consistent())
示例#10
0
# 1 Agregar contactos
# 2 Borrar contactos
# 3 Listar contactos
# 4 Buscar uno/unos contactos

from PhoneBookContact import PhoneBookContact
from PhoneBook import PhoneBook
from util import generarAgenda

agenda = PhoneBook()
generarAgenda(agenda, 150)


##########################
def agregar():
    telefono = int(input("\nindique el telefono: "))
    nombre = input("\nindique el nombre: ")
    correo = input("\nindique el correo: ")
    direccion = input("\nindique la direccion: ")

    contacto = PhoneBookContact(nombre, correo, telefono, direccion)
    agenda.add(contacto)


def listar():
    print(agenda)


def borrar():
    nombre = input("\nindique el nombre a buscar: ")
    lista = agenda.search(nombre)
示例#11
0
def main():
    #### HELPING MESSAGES ####
    helping_message = f'''{C.HEADER}                                  *** A Phone Book usage instruction ***{C.ENDC}
                   {C.MENU}>> /show_all   Shows all notes from the phone book.
                   >> /search     Search in the phone book by a particular field of fields.
                   >> /add_note   Add a new note to the phone book.
                   >> /del_note   Deleting an entry from the directory by first and last name or by phone number.
                   >> /change_field   Change any field or fields(surname, name...) in a specific directory entry.
                   >> /get_age        Shows the age of a particular person.
                   >> /show_bday_boy  Shows all people who have a birthday in the next 30 days. 
                   >> /quit           Leave the phone book.
                   >> /help           Show helping message.{C.ENDC}'''

    helping_message2 = f'''{C.HEADER}             !!! This Phone Book is empty !!!
    {C.WARNING}*{C.ENDC} {C.MENU}Now you can use just "/add_note" and "/quit" functions.
        >> /add_note   Add a new note to the phone book.
        >> /quit       Leave the phone book.{C.ENDC}'''

    hm = f'see {C.MENU}/help{C.ENDC} for assistance.'

    continue_info = f'\n>> Enter any command or {hm}'

    incorrect_input = f'{C.WARNING}>> *** INCORRECT INPUT! ***\n{C.ENDC}'

    _surname = f'>> Enter {C.RULES}surname{C.ENDC} ({C.WARNING}*{C.ENDC} ONLY: latin letters, numbers and ' \
               f'spaces)\nExamples: Ivanov, Ivanov15 or Bulwer Lytton. \n '
    _name = f'>> Enter {C.RULES}name{C.ENDC} ({C.WARNING}*{C.ENDC} ONLY latin letters, numbers and spaces)\nExamples: ' \
            f'Ivan, Liya15 or Anna Sofia). \n '

    _phone_number = f'>> Enter {C.RULES}phone number{C.ENDC} (ONLY 11 numbers!)\nTo work with MOBILE phone, enter: ' \
                    f'{C.RULES}M{C.ENDC} 89XXXXXXXXX\nTo work with WORK phone, enter: {C.RULES}W{C.ENDC} ' \
                    f'89XXXXXXXXX\nTo work with HOME phone, enter: {C.RULES}H{C.ENDC} 89XXXXXXXXX\nTo work with ' \
                    f'SEVERAL numbers, enter {C.RULES}S{C.ENDC} and fill in open fields:\n' \
                    f'{C.RULES}S (+enter){C.ENDC} -> then enter {C.RULES}89XXXXXXXXX{C.ENDC} to the open gaps or {C.RULES}"-"{C.ENDC} to skip.\n '

    _b_day = f'>> Enter {C.RULES}b-day{C.ENDC}: (DAY.MONTH.YEAR) -> 01.05.2001  OR "-" to skip.\n'
    ##################################################################################################

    ##### FILES WORK ####
    file_name = 'phone_book.csv'
    f = os.path.abspath(file_name)
    df = pd.read_csv(f)
    ########################################

    if not check_empty(df, helping_message2):
        print(helping_message)
    user_data = ''

    df.set_index(['surname', 'name'],
                 inplace=True)  # make name & surname as index

    pb = PhoneBook(df, file_name)

    ### THE MAIN WORK(loop) #####
    while True:
        if user_data == '/CHANGE':  # to change an existing note (after trying to add)
            user_data = '/change_field'
        else:
            user_data = input('>> ').strip()

        if user_data == '/help':  # HELP
            if not check_empty(pb.data, helping_message2):
                print(helping_message)
            continue
        ###########################################################################################################
        elif user_data == '/show_all':  # SHOW ALL
            pb.show_all_notes()
            print(continue_info)
            continue
        ###########################################################################################################
        elif user_data == '/search':  # SEARCH
            if check_empty(pb.data, helping_message2):
                print(continue_info)
                continue
            else:
                search_info = '>> Search by: "SURNAME" - "NAME" - "PHONE NUMBER(mobile, work, home)" - ' \
                              f'"B-DAY".\nIf you {C.RULES}DO NOT{C.ENDC} want to search by some of fields, put, pls: ' \
                              f'- .\n '
                print(search_info)

                _surname1 = f'>> Enter {C.RULES}full surname{C.ENDC} OR just the {C.RULES}1st letter{C.ENDC} OR' \
                            f' {C.RULES}-{C.ENDC} .\nExamples: Ivanov15, A or - .\n'
                _name1 = f'>> Enter {C.RULES}full name{C.ENDC} OR just the {C.RULES}1st letter{C.ENDC} OR ' \
                         f'{C.RULES}-{C.ENDC} .\nExamples: Ivan, L or -).\n'
                _phone_number1 = f'>> Enter {C.RULES}phone number{C.ENDC} (ONLY 11 numbers!):\nTo search by MOBILE ' \
                                 f'phone, enter: {C.RULES}M{C.ENDC} 89XXXXXXXXX\nTo search by WORK phone, enter: ' \
                                 f'{C.RULES}W{C.ENDC} 89XXXXXXXXX\nTo search by HOME phone, enter: ' \
                                 f'{C.RULES}H{C.ENDC} 89XXXXXXXXX\nOR "-" to skip'
                _b_day1 = f'>> Enter {C.RULES}full b-day{C.ENDC} OR just {C.RULES}a day{C.ENDC}: (DAY.MONTH.YEAR) -> ' \
                          f'01.05.2001  OR "-" to skip.\n '

                surname = input(f'{_surname1}>> ').capitalize().strip()
                name = input(f'{_name1}>> ').capitalize().strip()
                phone_number = input(f'{_phone_number1}>> ').replace(
                    '+7', '8').strip()
                arr_phone = [phone_number]
                b_day = input(f'{_b_day1}>> ').strip()
                if b_day == '':
                    b_day = '-'
                b_day = standardize_bday(b_day)

                mode = 'search'
                Flag = True
                while True:
                    s, n, arr_pn, bd = check_correct_input(
                        mode, surname, name, arr_phone, b_day)
                    if surname == name == phone_number == b_day == '-':
                        print(f"{C.WARNING}You entered ALL '-'.\n{C.ENDC}")
                        Flag = False
                        break
                    elif s and n and all(arr_pn) and bd:
                        break
                    else:
                        print(incorrect_input)
                        if not s:
                            surname = input(
                                f'{_surname1}>> ').capitalize().strip()
                        if not n:
                            name = input(f'{_name1}>> ').capitalize().strip()
                        if not all(arr_pn):
                            phone_number = input(
                                f'{_phone_number1}>> ').replace('+7',
                                                                '8').strip()
                            arr_phone.clear()
                            arr_phone.append(phone_number)
                        if not bd:
                            b_day = input(f'{_b_day1}>> ').strip()
                            if b_day == '':
                                b_day = '-'
                            b_day = standardize_bday(b_day)

                if Flag:
                    search_rez = pb.to_search(surname, name, phone_number,
                                              b_day)
                    print(tabulate(search_rez, tablefmt='fancy_grid'))
                print(f'\n>> Enter {C.MENU}/search{C.ENDC} again or', hm)
                continue
        ###########################################################################################################
        elif user_data == '/add_note':  # ADD NOTE
            add_info = '>> To ADD the Note, fill in the next fields, pls.'
            print(add_info)

            surname = input(f'{_surname}>> ').capitalize().strip()
            name = input(f'{_name}>> ').capitalize().strip()

            arr_phone = list()
            mobile_phone = ''
            work_phone = ''
            home_phone = ''
            phone_number = input(f'{_phone_number}>> ').replace('+7',
                                                                '8').strip()
            if re.search(r'[Ss]', phone_number):
                Flag = True
                while Flag:
                    print('Example: 89XXXXXXXXX or "-" to skip')
                    mobile_phone = 'M ' + input(f'MOBILE phone: ').replace(
                        '+7', '8').strip()
                    work_phone = 'W ' + input(f'WORK phone: ').replace(
                        '+7', '8').strip()
                    home_phone = 'H ' + input(f'HOME phone: ').replace(
                        '+7', '8').strip()
                    if mobile_phone.split(' ')[1] == work_phone.split(
                            ' ')[1] == home_phone.split(' ')[1] == '-':
                        print(
                            f"{C.WARNING}>> !!! You entered ALL '-'.\n   Pls, enter MOBILE/WORK/HOME phone number.\n{C.ENDC}"
                        )
                    else:
                        Flag = False

                arr_phone.extend([mobile_phone, work_phone, home_phone])
            else:
                arr_phone.append(phone_number)

            b_day = input(f'{_b_day}>> ').strip()
            if b_day == '':
                b_day = '-'
            b_day = standardize_bday(b_day)

            mode = 'add'
            # start input checks
            surname, name, arr_phone, b_day = start_input_checks(
                mode=mode,
                ii=incorrect_input,
                _s=_surname,
                _n=_name,
                _pn=_phone_number,
                _bd=_b_day,
                surname=surname,
                name=name,
                arr_phone=arr_phone,
                b_day=b_day)

            hp_msg = f'{C.WARNING}This entry: {surname} {name} already exists in the phone book.\nYou can ' \
                     'change it or go back to the menu and enter another' \
                     f' command.{C.ENDC}\n'
            hp_msg2 = f'Enter {C.MENU}/change_field{C.ENDC} or {C.MENU}/return.{C.ENDC}\n'

            rez = pb.add_note(surname, name, arr_phone, b_day)  # func call
            if rez == 'exist':
                print(hp_msg, hp_msg2)
                user_data = input('>> ')
                while True:
                    if user_data == '/change_field':
                        user_data = '/CHANGE'
                        break
                    elif user_data == '/return':
                        print(continue_info)
                        break
                    else:  # if input smth wrong
                        print(f'{C.WARNING}Incorrect input!{C.ENDC}\n',
                              hp_msg2)
                        user_data = input()
                continue
            else:
                print(continue_info)
                continue
        ###########################################################################################################
        elif user_data == '/del_note':  # DELETE NOTE
            if check_empty(pb.data, helping_message2):
                print(continue_info)
                user_data = input('>> ').strip()
            else:
                del_info = f'>> To {C.RULES}DELETE{C.ENDC} the Note, fill in the next fields, pls.\n' \
                           f'Delete by {C.RULES}SURNAME{C.ENDC} and {C.RULES}NAME{C.ENDC}, ' \
                           f'enter {C.RULES}"1"{C.ENDC}.\nDelete by {C.RULES}PHONE NUMBER{C.ENDC}, enter {C.RULES}"2"{C.ENDC}.\n'
                print(del_info)

                _phone_number2 = f'>> Enter {C.RULES}phone number{C.ENDC} (ONLY 11 numbers!)\nTo work with MOBILE phone, enter: ' \
                                 f'{C.RULES}M{C.ENDC} 89XXXXXXXXX\nTo work with WORK phone, enter: {C.RULES}W{C.ENDC} ' \
                                 f'89XXXXXXXXX\nTo work with HOME phone, enter: {C.RULES}H{C.ENDC} 89XXXXXXXXX\n'

                mode_del = input('1 or 2: >> ').strip()
                Flag = True
                while Flag:
                    if mode_del != '1' and mode_del != '2':
                        mode_del = input('1 or 2: >> ')
                    else:
                        Flag = False

                surname = None
                name = None
                phone_number = None
                mode = 'del'
                flag_exist = True
                if mode_del == '1':
                    surname = input(f'{_surname}>> ').capitalize().strip()
                    name = input(f'{_name}>> ').capitalize().strip()
                    mode_del = 'sn'
                    mode += ' 1'
                    surname, name = start_input_checks(mode,
                                                       ii=incorrect_input,
                                                       _s=_surname,
                                                       _n=_name,
                                                       surname=surname,
                                                       name=name)

                    existence = pb.to_search(surname, name, '-', '-')
                    if str(existence) == 'No such note.':  # if such note exist
                        flag_exist = False

                elif mode_del == '2':
                    phone_number = input(f'{_phone_number2}>> ').replace(
                        '+7', '8').strip()
                    arr_phone = [phone_number]
                    mode_del = 'num'
                    mode += ' 2'
                    phone_number = start_input_checks(mode,
                                                      ii=incorrect_input,
                                                      _pn=_phone_number2,
                                                      arr_phone=arr_phone)

                    existence = pb.to_search('-', '-', phone_number, '-')
                    if str(existence) == 'No such note.':  # if such note exist
                        flag_exist = False

                if flag_exist:
                    pb.del_note(mode_del, surname, name, phone_number)
                    print(continue_info)
                    continue
                else:
                    print(f'{C.WARNING}No note with such data!{C.ENDC}')
                    print(continue_info)
                    continue
        ###########################################################################################################
        elif user_data == '/change_field':  # CHANGE FIELD
            if check_empty(pb.data, helping_message2):
                print(continue_info)
                continue
            else:
                change_info = '>> To CHANGE the Note, 1st of all, enter, pls, SURNAME and NAME.'
                print(change_info)

                surname = input(
                    f'{_surname}\nOld surname: >> ').capitalize().strip()
                name = input(f'{_name}\nOld name: >> ').capitalize().strip()
                orig_surname = surname
                orig_name = name

                if pb.data.index.isin([(surname, name)
                                       ]).any():  # if such person exists
                    print(
                        f">> Enter, pls, a {C.RULES}NEW VALUE{C.ENDC} to the next fields, if u want to change them\n"
                        f"OR {C.RULES}'-'{C.ENDC} , if u {C.RULES}DON'T{C.ENDC} want to change them."
                    )
                    surname = input(f'{_surname}\nNew surname or -: >> '
                                    ).capitalize().strip()
                    name = input(
                        f'{_name}\nNew name or -: >> ').capitalize().strip()
                    if pb.data.index.isin([(surname, name)]).any():
                        print(
                            f'{C.WARNING}You try to change {C.ENDC}{orig_surname} {orig_name}{C.ENDC} {C.WARNING}to'
                            f' {C.ENDC}{surname} {name}{C.ENDC}{C.WARNING}.\n'
                            f'HOWEVER, {C.ENDC}{surname} {name}{C.ENDC}{C.WARNING} already exists!!!{C.ENDC}\n'
                        )
                        print(continue_info)
                        continue
                    else:
                        arr_phone = list()
                        mobile_phone = ''
                        work_phone = ''
                        home_phone = ''
                        phone_number = input(
                            f'{_phone_number}\nNew number or S or -: >> '
                        ).replace('+7', '8').strip()
                        if re.search(r'[Ss]', phone_number):
                            Flag = True
                            while Flag:
                                print('Example: 89XXXXXXXXX or "-" to skip')
                                mobile_phone = 'M ' + input(
                                    f'MOBILE phone: ').replace('+7',
                                                               '8').strip()
                                work_phone = 'W ' + input(
                                    f'WORK phone: ').replace('+7',
                                                             '8').strip()
                                home_phone = 'H ' + input(
                                    f'HOME phone: ').replace('+7',
                                                             '8').strip()
                                if mobile_phone.split(
                                        ' ')[1] == work_phone.split(
                                            ' ')[1] == home_phone.split(
                                                ' ')[1] == '-':
                                    print(
                                        f"{C.WARNING}>> !!! You entered ALL '-'.\n   Pls, enter some phone number("
                                        f"MOBILE/WORK/HOME).{C.ENDC}\n")
                                else:
                                    Flag = False

                            arr_phone.extend(
                                [mobile_phone, work_phone, home_phone])
                        else:
                            arr_phone.append(phone_number)

                        b_day = input(f'{_b_day}\nNew b-day or -: >> ').strip()
                        if b_day == '':
                            b_day = '-'
                        b_day = standardize_bday(b_day)

                        mode = 'change'
                        _surname += 'New surname or -: >> '
                        _name += 'New name or -: >> '
                        _phone_number += 'New number or -: >> '
                        _b_day += 'New b-day or -: >> '
                        # start input checks
                        surname, name, arr_phone, b_day = start_input_checks(
                            mode=mode,
                            ii=incorrect_input,
                            _s=_surname,
                            _n=_name,
                            _pn=_phone_number,
                            _bd=_b_day,
                            surname=surname,
                            name=name,
                            arr_phone=arr_phone,
                            b_day=b_day)

                        pb.change_field(orig_surname, orig_name, surname, name,
                                        arr_phone, b_day)
                        print(continue_info)
                        continue
                else:
                    print(
                        f"{C.WARNING}\n>> Such person ({surname} {name}) doesn't exist!{C.ENDC}"
                    )
                    print(continue_info)
                    continue
        ###########################################################################################################
        elif user_data == '/get_age':  # GET AGE
            if check_empty(pb.data, helping_message2):
                print(continue_info)
                continue
            else:
                get_age_info = '>> To GET AGE of a person, fill in the next fields, pls.'
                print(get_age_info)

                surname = input(f'{_surname}>> ').capitalize().strip()
                name = input(f'{_name}>> ').capitalize().strip()

                mode = 'get_age'

                surname, name = start_input_checks(mode,
                                                   ii=incorrect_input,
                                                   _s=_surname,
                                                   _n=_name,
                                                   surname=surname,
                                                   name=name)

                pb.get_age(surname, name)
                print(continue_info)
                continue
        ###########################################################################################################
        elif user_data == '/show_bday_boy':  # SHOW B-DAY BOY
            people = pb.show_bday_boy()
            for num, person in enumerate(people, start=1):
                print(num, '. ', person)
            print(continue_info)
            continue
        ###########################################################################################################
        elif user_data == '/quit':  # QUIT
            print(f'{C.HEADER}*** GOOD BYE! ***{C.ENDC}')
            break
        ###########################################################################################################
        else:  # if u enter wrong requirement
            print(f"{C.WARNING}*** There's NO such option! ***\n{C.ENDC}")
            print(continue_info)
            continue
示例#12
0
        6 - Logout
        """)
        choice = (input("\nEnter Choice >> "))

        if choice == '1':  # CREATE NEW CONTACT

            first_name = input("First Name\t: ")
            last_name = input("Last Name\t: ")
            gender = input("M / F\t: ")
            phone = input("Phone(03xx-xxxxxxx)\t: ")
            city = input("City\t: ")
            country = input("Country\t: ")
            zip_code = input("Zip Code\t: ")
            print("--------------")
            try:  # try to create new object
                contact = PhoneBook(first_name, last_name, gender, phone, city,
                                    country, zip_code)
            except InvalidPhoneException as e:
                print(e)
                continue
            except InvalidGenderException as e:
                print(e)
                continue
            except InvalidZipException as e:
                print(e)
                continue
            except InvalidCityNameException as e:
                print(e)
                continue
            except InvalidCountryNameException as e:
                print(e)
                continue  # go back and show the menu again
示例#13
0
    print("Contact: Larry Gates - (48126879)")
    print("Contact: Sup a man - (48430546)")
    print("Contact: This Little Name - (26979487)")
    print("Your Results ~~~~~~~~~~~~~~~~~~~")
    print(c1)
    print(c2)
    print(c3)
    print(c4)

    ########################################################################
    # Testing Phonebook
    ########################################################################
    print("~" * 60)
    print("{:^60}".format("Testing PhoneBook Class"))
    print("~" * 60)
    PB = PhoneBook()  # Initializes a instance of the class PhoneBook

    print("Testing get_all_contacts (addContact)")
    get_all_contacts(PB)
    # We do not need to return the PhoneBook instance because
    #   we are modifying the variable in memory

    print()
    print(PB)

    print()
    print("-" * 30)
    print("Testing addContact with a dictionary")
    tempD = {
        "name": ['Nick', 'J', 'Mobley'],
        "number": 8123357216,