-#XXX doesn't work - cf https://github.com/ecederstrand/exchangelib/issues/492
-def add_ex_to_gcal_needs_ev_id(ex_cal,events):
- for ev_id in events:
- print(ev_id)
- event = get_ex_event_by_uid(ex_cal,ev_id)
- event.gcal_link = "Testing"
- event.save()
+def rrule_from_ex(event,gcal_tz):
+ if event.type != "RecurringMaster":
+ logger.error("Cannot make recurrence from not-recurring event")
+ return None
+ if event.recurrence is None:
+ logger.error("Empty recurrence structure")
+ return None
+ if isinstance(event.recurrence.pattern,
+ exchangelib.recurrence.DailyPattern):
+ rr = "RRULE:FREQ=DAILY;INTERVAL=%d" % event.recurrence.pattern.interval
+ else:
+ logger.error("Recurrence %s not supported" % event.recurrence)
+ return None
+ if isinstance(event.recurrence.boundary,
+ exchangelib.recurrence.EndDatePattern):
+ rr += ";UNTIL={0:%Y}{0:%m}{0:%d}".format(event.recurrence.boundary.end)
+ else:
+ logger.error("Recurrence %s not supported" % event.recurrence)
+ return None
+ if event.modified_occurrences is not None or \
+ event.deleted_occurrences is not None:
+ logger.warning("Modified/Deleted recurrences not supported")
+ return [rr]
+
+def build_gcal_event_from_ex(event,gcal_tz):
+ gevent={}
+ gevent["summary"]=event.subject
+ if event.is_all_day:
+ gevent["end"]={"date": str(event.end.astimezone(gcal_tz).date())}
+ gevent["start"]={"date": str(event.start.astimezone(gcal_tz).date())}
+ else:
+ gevent["end"]={"dateTime": event.end.astimezone(gcal_tz).isoformat(),
+ "timeZone": str(gcal_tz)}
+ gevent["start"]={"dateTime": event.start.astimezone(gcal_tz).isoformat(),
+ "timeZone": str(gcal_tz)}
+ if event.text_body is not None and event.text_body.strip() != '':
+ gevent["description"] = event.text_body
+ if event.location is not None:
+ gevent["location"] = event.location
+ gevent["extendedProperties"]={"shared": {"ex_id": event.item_id}}
+ return gevent