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")
def modify_existing_contact(self): updated = False contact_id = int(input('Whose contact do you wish to edit? (type in ID please) ')) while not updated: print('[1] First Name') print('[2] Last Name') print('[3] Email') print('[4] Note') mod_choice = input('What would you like to change? ') if int(mod_choice) >= 1 and int(mod_choice) <= 4: mod_contact = Contact.find(contact_id) if int(mod_choice) == 1: first_name_change = input('What would you like to change the first name to?: ') mod_contact.update('first_name', first_name_change) updated = True elif int(mod_choice) == 2: last_name_change = input('What would you like to change the last name to?: ') mod_contact.update('last_name', last_name_change) updated = True elif int(mod_choice) == 3: email_change = input('What would you like to change the email to?: ') mod_contact.update('email', email_change) updated = True elif int(mod_choice) == 3: note_change = input('What would you like to change the note to?: ') mod_contact.update('note', note_change) updated = True else: print('Please enter one of the following numbers')
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.')
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)
def modify_existing_contact(self): print("Please select the id of the contact you would like to modify") 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.update(contact_detail)
def modify_existing_contact(self): user_id = int( input("Enter the id of the contact you wish to update: ")) selected_contact = Contact.find(user_id) print("Select an attribute to change") print("1 - First Name") print("2 - Last Name") print("3 - Email") print("4 - Note") attribute = int(input("Enter the number of attribute to be changed: ")) new_value = input("Enter the new info:") if attribute == 1: selected_contact.update('first name', new_value) elif attribute == 2: selected_contact.update('last name', new_value) elif attribute == 3: selected_contact.update('email', new_value) elif attribute == 4: selected_contact.update('note', new_value)
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()
print("Current number of contacts:") print(len(Contact.contacts)) print() print("Contacts ids:") print(contact1.id) print(contact2.id) print(contact3.id) print() print("Current list of contacts:") print(Contact.all()) print() requested_id = 3 print("Find contact with id of {}:".format(requested_id)) print(Contact.find(requested_id)) print() print("Successfully updating a contact:") contact1.update("first_name", "Elizabeth") print(contact1) print() print("Failed attempt to update a contact:") print(contact1.update("first name", "Bettie")) print(contact1) print() print("Successfully finding a contact by attribute name and value:") print(Contact.find_by('first_name', 'Elizabeth'))
def delete_contact(self): contact_id = int(input('Whose contact do you wish to edit? (type in ID please) ')) del_contact = Contact.find(contact_id) del_contact.delete()
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()