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 to remove or change a calendar event?

    Pythonista
    5
    23
    9043
    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.
    • cvp
      cvp @ccc last edited by cvp

      @ccc I know, but here we need Objectivec NSDateFormatter objects

      1 Reply Last reply Reply Quote 1
      • ccc
        ccc last edited by

        Yes. My point was about converting from Python datetimes to Objective C datetimes.

        1 Reply Last reply Reply Quote 1
        • AA737
          AA737 @cvp last edited by

          @cvp said:

          @AA737 Thanks to @JonB , this works

          import datetime
          import objc_util
          
          with objc_util.autoreleasepool():
          	
          	# EKEventStore = calendar database
          	store = objc_util.ObjCClass('EKEventStore').alloc().init()
          	
          	# Convert string yyyymmdd to NSdate
          	dateFormat = objc_util.ObjCClass('NSDateFormatter').alloc().init()
          	dateFormat.setDateFormat_('yyyyMMdd HH:mm')
          
          	date1 = dateFormat.dateFromString_('20200101 00:01') 
          	date2 = dateFormat.dateFromString_('20201231 23:59')  
          
          	calendars_array = [calendar for calendar in store.calendars() if str(calendar.title()) == 'Sorties']
          	predicate = store.predicateForEventsWithStartDate_endDate_calendars_(date1, date2, calendars_array)
          	events = store.eventsMatchingPredicate_(predicate)
          	for event in events:
          		print(event.title())
          		
          	store.autorelease()
          	
          del events, predicate, store, calendars_array 
          

          Fantastic, thanks @cvp and @JonB !

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