Forum Archive

Edit a contact iOS

3ryck

Hello guys, it’s time for me to use this app (i bought it 2 years ago lol)

Now I’m trying to get one specific contact, i read the documentation and i could managed to get/retrieve the contact, but when i attempt to edit its phone value, it’s not saving it. Even with “contact.save()” at the end. Any help please? Thanks
```
import contacts
import clipboard

DEFAULT_CONTACT = 'Temporal'
curr_cb = clipboard.get()
people = contacts.get_all_people()
for p in people:
if p.first_name == DEFAULT_CONTACT:
p.phone[0] = [(contacts.MAIN_PHONE, int(curr_cb))]
print(p.first_name + ' ' + p.phone[0][1])
contacts.save()
break
print(p.phone)
contacts.save() ```

JonB

https://github.com/omz/Pythonista-Issues/issues/205
Might be related?

Have you tried opening contacts to see if your update show up there? It may be that it just doesn't get updated within pythonista..

cvp

@3ryck that does not solve the problem (save does not work), but I think (perhaps erroneously) that
1) telephone n° (curr_cb) is a string, not an int
2) p.phone[0] is a tuple, not an array of tuples (p.phone is an array)

       p.phone[0] = (p.phone[0][0],curr_cb) 
LenaCharles

@3ryck Thanks alot for the awesome information that you shared on this code.

3ryck

Hi, I’m back... and yesterday i was recalling this forum, i just came by to tell you my experience.

*Now it works and was easy to solve but difficult to get it there, because it seems is some app issue. I had to close and re-open the app as if it needs to refresh all variables or objects, idk.
I noticed it when i was working on this code, it worked okay and then i took a 15mins break, but when i was back to Pythonista; it suddenly stop working... <> Well i debugged it and i could see ‘contacts.Person()’ fields being changed and ‘saved’ correctly, BUT those updates only showed up within Pythonista, and not in My Contacts app. It was like if Pythonista retrieved all my contacts from a different app or memory.
Well, after trying changing the code here and there without any success, i just closed the app(slide up) and re-open it, and voila, my code was working again, all contacts’ updates were mirrored in my contacts app.

Now, the code i was testing and worked fine as example. (You can use get_all_people() instead of find() )

```import contacts
import clipboard

primer_valor_de_lista = 0
curr_cb = clipboard.get()
temp_contact = contacts.find('Temporal')
person = temp_contact[primer_valor_de_lista]

print(person.first_name)

converted = int(curr_cb)

print(curr_cb)

person.phone = [(contacts.MAIN_PHONE, curr_cb)]

temp_contact[primer_valor_de_lista]=person

contacts.save()

print(person.phone[0])

Insert Code Here
```