예제 #1
0
def contact_book():
    contact_book = ContactBook()

    try:
        with open('contacts.csv', 'r') as f:
            reader = csv.reader(f)
            for idx, row in enumerate(reader):
                if idx == 0:
                    continue
                contact_book.add(row[0], row[1], row[2])
    except:
        pass

    return render_template('contact_book.html',
                           contacts=contact_book._contacts)
예제 #2
0
def main():

    stores = {'db': binary_store, 'json': json_store}

    path = input('store path?')

    ext = path.split('.')[-1]
    mod = stores.get(ext, binary_store)

    store = mod.Store(path)
    contactBook = ContactBook(store)
    if (input('add dummy records?') == 'YES'):
        add_dummy_contacts(contactBook)

    actions = {
        1: add_contact,
        2: list_contact,
        3: search_contact,
        4: save_contact,
        5: load_contact,
        0: exit_app,
    }

    while True:
        action = menu(actions)
        action(contactBook)
예제 #3
0
def delete_contact(email):

    if request.form:
        contact_book = ContactBook()
        try:
            if request.form.get('password') == os.environ.get(
                    'PASSWORD_CONTACTS'):
                with open('contacts.csv', 'r') as f:
                    reader = csv.reader(f)
                    for idx, row in enumerate(reader):
                        if idx == 0:
                            continue
                        contact_book.add(row[0], row[1], row[2])
                        contact_book.delete(email)
        except:
            pass

    return redirect('/')
예제 #4
0
파일: main.py 프로젝트: fidekof/PythonTest
def run():
    option = ''
    book = ContactBook()
    while option != 'S':
        option = str(
            input('**********************\n'
                  '[A]gregar\n'
                  '[E]liminar\n'
                  '[L]istar\n'
                  '[S]alir\n'
                  '***********************\n'
                  'Elija su opcion: '))
        if (option == 'A'):
            c = Contact()
            c._name = str(input('Nombre: '))
            c._lastname = str(input('Apellido: '))
            c._phone = str(input('Telefono: '))
            c._email = str(input('Email: '))
            book.add_contact(c)
        elif (option == 'L'):
            book.listar()
예제 #5
0
def add_contact():

    if request.form:
        contact_book = ContactBook()

        if request.form.get('password') == os.environ.get('PASSWORD_CONTACTS'):
            try:
                with open('contacts.csv', 'r') as f:
                    reader = csv.reader(f)
                    for idx, row in enumerate(reader):
                        if idx == 0:
                            continue
                        contact_book.add(row[0], row[1], row[2])
            except:
                pass

            contact_book.add(request.form.get('name'),
                             request.form.get('phone'),
                             request.form.get('email'))
            flash('Contact added successfully')

    return render_template('add_contact.html')
# call add_phone on don
don.add_phone("12345678", "work")
print(don)

# create contact for Roosevelt Franklin
roosevelt = Contact("Roosevelt", "Franklin")

# call add_email() on roosevelt
roosevelt.add_email("*****@*****.**")
roosevelt.add_email("*****@*****.**")

# call print_emails()
roosevelt.print_emails()

# create a contact book
sesame_street = ContactBook()

# add contacts to contact book
sesame_street.add(cookie)
sesame_street.add(don)
sesame_street.add(roosevelt)

# print the number of contacts in contact book
print(len(sesame_street.contacts))

# print all contacts
sesame_street.print_all_contacts()

# print book
sesame_street.print_book()
예제 #7
0
파일: main.py 프로젝트: ZeusXD/Python_test
def run():

    contact_book = ContactBook()

    contact_book.read_csv()

    while True:
        command = str(
            input('''
            ¿Qué deseas hacer?

            [a]ñadir contacto
            [ac]tualizar contacto
            [b]uscar contacto
            [e]liminar contacto
            [l]istar contactos
            [s]alir
        '''))

        if command == 'a':
            name = str(input('Escribe el nombre: '))
            phone = str(input('Escribe el telefono: '))
            email = str(input('Escribe el email: '))

            contact_book.add(name, phone, email)

        elif command == 'ac':
            name = str(input('Escribe el nombre: '))
            contact_book.update(name)

        elif command == 'b':
            name = str(input('Escribe el nombre: '))
            contact_book.search(name)

        elif command == 'e':
            name = str(input('Escribe el nombre: '))
            contact_book.delete(name)

        elif command == 'l':
            contact_book.show_all()

        elif command == 's':
            break
        else:
            print('Comando no encontrado.')
예제 #8
0
def run():
    contact_book = ContactBook()
    try:
        contact_book.load()
    except:
        print('No existen contactos actualmente!. agregue al primero')

    while True:
        command = input('''
        ¿Qué desea hacer?

        [a]gregar contacto
        [ac]tualizar contacto
        [b]uscar contacto
        [l]istar contactos
        [e]liminar contacto
        [s]alir
        ''')

        if command == 'a':
            name = input('Escribe el nombre del contacto:\n')
            phone_number = input('Escribe el telefono del contacto:\n')
            email = input('Escribe el email del contacto:\n')
            contact_book.add(name, phone_number, email)
            print('Contacto Añadido')
        elif command == 'ac':
            name = input('Escribe el nombre del contacto:\n')
            while True:
                ac_command = input('''
                ¿Qué deseas modificar?

                [n]ombre
                [te]lefono
                [c]orreo electronico
                [t]odo
                [ca]ncelar
                ''')
                if ac_command == 'n':
                    new_name = input('Escribe el nuevo nombre:\n')
                    contact_book.update(name, new_name=new_name)
                    break
                elif ac_command == 'te':

                    new_phone_number = input('Escribe el nuevo telefono:\n')
                    contact_book.update(
                        name, new_phone_number=new_phone_number)
                    break
                elif ac_command == 'c':
                    new_email = input('Escribe el nuevo correo electronico:\n')
                    contact_book.update(name, new_email=new_email)
                    break
                elif ac_command == 't':
                    new_name = input('Escribe el nuevo nombre:\n')
                    new_phone_number = input('Escribe el nuevo telefono:\n')
                    new_email = input('Escribe el nuevo correo electronico:\n')
                    contact_book.update(
                        name, new_name=new_name, new_phone_number=new_phone_number, new_email=new_email)
                    break
                elif ac_command == 'ca':
                    print('Volviendo al menu principal')
                    break
                else:
                    print('Opcion invalida')
        elif command == 'b':
            name = input('Escribe el nombre del contacto:\n')
            contact_book.search(name)
        elif command == 'l':
            contact_book.show_all()
        elif command == 'e':
            name = input('Escribe el nombre del contacto a eliminar:\n')
            contact_book.delete_contact(name)
            print('Contacto eliminado satisfactoriamente')
        elif command == 's':
            print('Hasta pronto...')
            break
        else:
            print('Opcion invalida.')
        [r]emove a contact
        [l]ist all your contacts
        [e]xit
        '''))

        if (command == 'a'):
            name = str(raw_input("Input the contacts name: "))
            phone = str(raw_input("Input the contacts phone: "))
            email = str(raw_input("Input the contacts email: "))
            contact_book.add(name, phone, email)
        elif (command == 'u'):
            name = str(raw_input("Input name contact to update: "))
            contact_book.update(name)
        elif (command == 's'):
            name = str(raw_input("Input name contact to show: "))
            contact_book.searchAndPrint(name)
        elif (command == 'r'):
            name = str(raw_input("Input name contact to delete: "))
            contact_book.remove(name)
        elif (command == 'l'):
            contact_book.show_contacts()
        elif (command == 'e'):
            print("Goodbye")
            return
        else:
            print("I couldn't understand that commend, try again")


if __name__ == "__main__":
    contact_book = ContactBook()
    run()
예제 #10
0
def generate_contacts():

    # create a contact book
    sesame_street = ContactBook()

    # create contact for Cookie Monster
    cookie = Contact("cookie", "Cookie", "Monster")

    # call add_phone() on cookie
    cookie.add_phone("12345678", "work")
    cookie.add_phone("00123456", "Cookie Line")
    cookie.add_label("Cookie")
    cookie.add_label("Friend")
    cookie.add_label("Friends with Ernie")

    cookie.add_email("*****@*****.**")
    cookie.update_biography(
        "Some quick example text to build on the card title and make up the bulk of the card's content."
    )

    # create contact for Don Music
    don = Contact("don", "Don", "Music")

    # call add_label on don
    don.add_label("Music")
    don.add_label("Friend")

    # call add_phone on don
    don.add_phone("12345678", "work")

    # add avatar
    don.avatar_url = "https://vignette.wikia.nocookie.net/muppet/images/c/c3/Don_Music.png/revision/latest/scale-to-width-down/280?cb=20110808141055"

    # create contact for Roosevelt Franklin
    roosevelt = Contact("frankr", "Roosevelt", "Franklin")

    # call add_phone on don
    roosevelt.add_phone("12345678", "personal")

    # call add_email() on roosevelt
    roosevelt.add_email("*****@*****.**")
    roosevelt.add_email("*****@*****.**")

    # set the avatar
    roosevelt.avatar_url = "https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fmuppetmindset.files.wordpress.com%2F2014%2F06%2Froosevelt-franklin.png%3Fw%3D251%26h%3D300&f=1&nofb=1"
    roosevelt.add_friend(don)

    # create contact for Bert
    bert = Contact("bert", "Bert", "Sesame")
    bert.add_email("*****@*****.**")
    bert.add_label("Bert from Sesame")
    bert.add_label("Friends with Ernie")
    bert.add_label("Friend")
    bert.update_biography(
        "Bert is Ernie's best friend and roommate on Sesame Street. The pair share the basement apartment at 123 Sesame Street."
    )
    bert.avatar_url = "https://vignette.wikia.nocookie.net/muppet/images/e/e1/Bert_smile.png/revision/latest/scale-to-width-down/280?cb=20110630173259"

    bert.add_friend(cookie)
    cookie.add_friend(bert)

    roosevelt.add_friend(bert)

    # add contacts to contact book
    sesame_street.add(cookie)
    sesame_street.add(don)
    sesame_street.add(roosevelt)
    sesame_street.add(bert)

    return sesame_street