Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- phone_contacts = data['contacts']
- contact_list = []
- set_of_all_phone_numbers = []
- # pymongo call
- contacts = database_read('contact', {'phone_number' : {'$in' : phone_book}, 'id1' : user_id})
- for con in contacts:
- con.update({ 'status' : 'active' })
- contact_to_send = {
- 'id' : con['id2'],
- 'phone_number' : con['phone_number']
- }
- contact_list.append(contact_to_send)
- set_of_all_phone_numbers.append(con['phone_number'])
- # get phone numbers taht are not in contacts
- new_contacts = set(phone_contacts) - set(set_of_all_phone_numbers)
- for number in new_contacts:
- new_contact = add_new_contact(number, user)
- contact_to_send = {
- 'id' : new_contact['id2'],
- 'phone_number' : new_contact['phone_number']
- }
- contact_list.append(contact_to_send)
- def add_new_contact(phone_number, user):
- """ adds a new contact to database as a current user's contact """
- # search for user in user collection
- phone_contact_obj = find_user_by_phone_number(phone_number)
- if not phone_contact_obj:
- # creates new user if not presetn
- phone_contact_obj = create(phone_number)
- # writes a contact in contact collection. args are left out on purpose
- contact = database_add_new_contact(args)
- return contact
Add Comment
Please, Sign In to add comment