Example #1
0
 def delete_contact(self):
     print("\n--DELETE CONTACT--\n")
     print("Please enter their ID:")
     id = int(input())
     print(Contact.select(id))
     Contact.delete(Contact.find(id))
     print(f'{id}, is now deleted.')
Example #2
0
    def delete_contact(self):
        contact_id = input("Enter the id of the contact you want to delete: ")

        contact_to_delete = Contact.find(contact_id)
        Contact.delete(contact_to_delete)

        print("Successfully deleted contact")
Example #3
0
 def delete_contact(self):
     if len(Contact.list_of_contacts) == 0:
         print("Error, no contacts to delete")
     else:
         id_to_delete = int(
             input(
                 "please enter the contact id you would like to delete: "))
         Contact.delete(id_to_delete - 1)
Example #4
0
 def delete_contact(self):
     print("Please select the id of the contact you would like to delete")
     for contact in Contact.contacts:
         print("{} {} {}".format(contact.id, contact.first_name,
                                 contact.email))
     input_id = int(input())
     contact_detail = Contact.find(input_id)
     Contact.delete(contact_detail)
Example #5
0
 def delete_all_contacts(self):
     print('\nDelete all contacts')
     print('Please enter \'yes\' to confirm:')
     if input() == 'yes':
         # Contact.delete_all()
         Contact.delete().execute()
         print('Your contacts have been deleted.')
     else:
         print('Returning to main menu.')
Example #6
0
def main(args):
    sys.argv = args
    args = docopt(__doc__)
    contact = Contact()
    # contact.set_bday(args["--bday"])
    schema = Schema({
        '--contact_id':
        Or(
            None,
            And(
                Use(int),
                Use(contact.set_cid,
                    error='id is not correct, it should be integer number'))),
        '--first_name':
        Or(None, Use(contact.set_fname, error='fname is not correct')),
        '--last_name':
        Or(None, Use(contact.set_lname, error='lname is not correct')),
        '--middle_name':
        Or(None, Use(contact.set_mname, error='mname is not correct')),
        '--phone':
        Or(None, Use(contact.set_phone, error='phone is not correct')),
        '--bday':
        Or(
            None,
            Use(contact.set_bday,
                error='birtday is not correct it should be one of the formats '
                + str(contact.bday_types))),
        '--data':
        Or(None, Use(set_data, error='name was not correct')),
        '--reverse':
        Or(None, True, False),
        '--replace':
        Or(None, True, False),
        '--sort':
        Or(None,
           "fname",
           "lname",
           "mname",
           "phone",
           "bday",
           error="--sort should be one of the fname,lname,mname,phone,bday"),
        'add':
        Or(False, True),
        'del':
        Or(False, True),
        'find':
        Or(False, True),
        'list':
        Or(False, True),
    })
    try:
        schema.validate(args)
    except SchemaError as e:
        exit(e)
    try:
        connection = sqlite3.connect(database)
        c = connection.cursor()
        c.execute(
            "create table contacts(id integer primary key autoincrement, fname text, lname text, mname text, phone text, bday text)"
        )
        print("new database " + database + " was created")
    except sqlite3.Error as e:
        print("Existing database " + database)

    if args["add"]:
        added, phoneexist, comment = contact.add(contact, c, args)
        if added:
            print(comment + " " + str(contact.get_tuple()))
        else:
            print(comment)
    elif args["find"]:
        finded = contact.find(contact, c)
        if finded:
            print(
                tabulate(finded,
                         headers=[
                             "Id", "first name", "last name", "middle name",
                             "phone", "birthday date"
                         ]))
        else:
            print("there is no any contact " +
                  (("like:" + str(contact)) if str(contact) else ""))
    elif args["del"]:
        result, string = contact.delete(contact, c)
        print(string)
        if result:
            for r in result:
                print(r)
        else:
            sys.exit(-1)
    elif args["list"]:
        result = contact.lst(args, c)
        if result:
            print(
                tabulate(result,
                         headers=[
                             "ID", "first name", "last name", "middle name",
                             "phone", "birthday date"
                         ]))
        else:
            print("there is empty database=" + database)

    else:
        remind = contact.reminder(c)
        print(
            "This contact will have their birthdays in this and next months:")
        if remind:
            print(
                tabulate(remind,
                         headers=[
                             "Id", "first name", "last name", "middle name",
                             "phone", "birthday date"
                         ]))

    connection.commit()
    connection.close()
Example #7
0
print("Deleting all contacts:")
Contact.delete_all()
print(Contact.contacts)

print()
print("Adding the 3 contacts back:")
contact1 = Contact.create('Betty', 'Maker', '*****@*****.**', 'Loves Pokemon')
contact2 = Contact.create('Bit', 'Bot', '*****@*****.**', 'beep boop')
contact3 = Contact.create('Anton', 'Moiseev', '*****@*****.**', 'Loves cats')
print(contact1)
print(contact2)
print(contact3)
print(Contact.contacts)

print()
print("Get full name of each contact:")
for contact in Contact.contacts:
    print(contact.full_name())

print()
print("Deleting a contact successfully:")
contact1.delete()
print(Contact.contacts)
for contact in Contact.contacts:
    print(contact)

print()
print("Failing to delete a contact:")
contact4 = Contact('Mia', 'Monteiro', '*****@*****.**', 'Loves to cook')
print(contact4.delete())
Example #8
0
 def delete_contact(self):
     id_to_delete = int(
         input('Enter the index number you would like to delete: '))
     Contact.delete(id_to_delete - 1)
def main(args):
    sys.argv=args
    args= docopt(__doc__)
    contact = Contact()
    # contact.set_bday(args["--bday"])
    schema = Schema({
        '--contact_id': Or(None,And(Use(int),Use(contact.set_cid, error='id is not correct, it should be integer number'))),
        '--first_name': Or(None,Use(contact.set_fname, error='fname is not correct')),
        '--last_name': Or(None,Use(contact.set_lname, error='lname is not correct')),
        '--middle_name': Or(None,Use(contact.set_mname, error='mname is not correct')),
        '--phone': Or(None,Use(contact.set_phone, error='phone is not correct')),
        '--bday': Or(None,Use(contact.set_bday, error='birtday is not correct it should be one of the formats ' + str(contact.bday_types))),
        '--data': Or(None,Use(set_data, error='name was not correct')),
        '--reverse': Or(None,True,False),
        '--replace': Or(None,True,False),
        '--sort': Or(None,"fname","lname","mname","phone","bday", error="--sort should be one of the fname,lname,mname,phone,bday"),
        'add': Or(False,True),
        'del': Or(False, True),
        'find': Or(False,True),
        'list': Or(False,True),
        })
    try:
        schema.validate(args)
    except SchemaError as e:
        exit(e)
    try:
        connection = sqlite3.connect(database)
        c = connection.cursor()
        c.execute("create table contacts(id integer primary key autoincrement, fname text, lname text, mname text, phone text, bday text)")
        print("new database " + database + " was created")
    except sqlite3.Error as e:
        print("Existing database " + database)

    if args["add"]:
        added, phoneexist, comment = contact.add(contact, c, args)
        if added:
            print(comment+" " + str(contact.get_tuple()))
        else:
            print(comment)
    elif args["find"]:
        finded=contact.find(contact, c)
        if finded:
            print(tabulate(finded, headers=["Id","first name","last name","middle name","phone","birthday date"]))
        else:
            print("there is no any contact "+(("like:"+str(contact)) if str(contact) else ""))
    elif args["del"]:
        result, string=contact.delete(contact, c)
        print(string)
        if result:
            for r in result:
                print(r)
        else:
            sys.exit(-1)
    elif args["list"]:
        result = contact.lst(args, c)
        if result:
            print(tabulate(result, headers=["ID","first name","last name","middle name","phone","birthday date"]))
        else:
            print("there is empty database="+database)

    else:
        remind=contact.reminder(c)
        print("This contact will have their birthdays in this and next months:")
        if remind:
            print(tabulate(remind, headers=["Id","first name","last name","middle name","phone","birthday date"]))

    connection.commit()
    connection.close()
Example #10
0
 def test_del_empty(self):
     contact = Contact()
     result, string=Contact.delete(contact, self.c)
     self.assertFalse(result)
Example #11
0
 def test_del(self):
     self.test_add()
     if self.added:
         contact = self.added[-1]
         result, string=Contact.delete(contact, self.c)
         self.assertTrue(result)
Example #12
0
 def delete_contact(self):
     print('What contact would you like to Delete?')
     print('Enter ID: ')
     self.id = input()
     Contact.delete(self)
Example #13
0
        if options == '1':
            system('cls')
            contact.add(list_of_contacts, dic)

        elif options == '2':
            system('cls')
            search_to_delete = input('{:>75}'.format(
                'Who are you looking for to delete? ')).upper().strip()
            # Shows who is going to be deleted
            if contact.search(list_of_contacts, dic, search_to_delete) == True:
                contact.show_wanted_contact(list_of_contacts, dic,
                                            search_to_delete)
                delete = input('{:>75}'.format(
                    'Type the contact phone number that you wanna delete: ')
                               ).strip()
                if contact.delete(list_of_contacts, dic, delete) == True:
                    contact.del_contact(list_of_contacts, dic, delete)
                    print(f'{search_to_delete:>70} has been deleted.')
                else:
                    print('{:^150}'.format('Incorrect! Try again!'))
            else:
                print(f'{search_to_delete:^150} was not found.')

        elif options == '3':
            system('cls')
            search_to_change = input('{:>75}'.format(
                'Who are you looking for to change? ')).upper().strip()
            # Shows who is going to be changed
            if contact.search(list_of_contacts, dic, search_to_change) == True:
                contact.show_wanted_contact(list_of_contacts, dic,
                                            search_to_change)