omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    How can add_group() be used?

    Pythonista
    2
    3
    1405
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • sgamel
      sgamel last edited by

      Hi,

      I’m trying to use the add_group function in Pythonista.
      I create a group object, set a name and call save.

      Seems that save fails with error, but I see no details in the console.

      Anything that I missed ?

      Here is my code:

      import contacts
      
      print('Groups {0.name!r}'.format(groupNames)) 
      
      allowed = contacts.is_authorized()
      print('Access to contacts allowed: {!r}'.format(allowed))
      
      group = contacts.Group()
      group.name = 'testing'
      print('Group {!r} - id: {!r}'.format(group.name, group.id))
      
      state = contacts.add_group(group)
      print('add group response: {!r}'.format(state))
      
      state = contacts.save()
      print('save response: {!r}'.format(state))
      
      print('Group {!r} - id: {!r}'.format(group.name, group.id))
      
      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @sgamel last edited by

        @sgamel that works

        import contacts
        # print all groups
        gs = contacts.get_all_groups()
        for g in gs:
        	print(g.name)
        # add one group
        g = contacts.Group()
        g.name = 'test group'
        contacts.add_group(g)
        contacts.save()
        # remove all groups
        gs = contacts.get_all_groups()
        for g in gs:
        	print(g.name)
        	contacts.remove_group(g)
        
        1 Reply Last reply Reply Quote 0
        • sgamel
          sgamel last edited by

          I had an error because initially my default contact container was Google Exchange. I did change to iCloud and this should have fixed the issue.

          But it didn’t. I had to kill Pythonista and rerun my script to get my script run without arrow.

          My guess is that Pythonista kept the reference to Google contacts in some way and did not take my change into account.

          It is now working. Thanks for your reply.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors