Fixed deletion of removed events

This commit is contained in:
Edgar P. Burkhart 2020-10-03 18:53:41 +02:00
parent 2857556170
commit fd2219ca8c
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227

View file

@ -48,6 +48,7 @@ class GoogleSheetsCalParser(HTMLParser):
self.date = {} self.date = {}
self.event = Event() self.event = Event()
self.event['uid'] = 0 self.event['uid'] = 0
self.uids = []
import priv import priv
@ -56,8 +57,6 @@ class GoogleSheetsCalParser(HTMLParser):
self.calendar = caldav.Calendar(client=client, url=CALURL) self.calendar = caldav.Calendar(client=client, url=CALURL)
#print(self.calendar.event_by_uid('42x26').data) #print(self.calendar.event_by_uid('42x26').data)
#for ev in progressbar(self.calendar.events()):
# print(ev.url, ev.canonical_url())
HTMLParser.__init__(self) HTMLParser.__init__(self)
@ -99,18 +98,19 @@ class GoogleSheetsCalParser(HTMLParser):
cal.add('version', '2.0') cal.add('version', '2.0')
cal.add_component(self.event) cal.add_component(self.event)
self.uids.append(self.event['uid'])
try: try:
ev = self.calendar.event_by_uid(self.event['uid']) ev = self.calendar.event_by_uid(self.event['uid'])
except caldav.lib.error.NotFoundError: except caldav.lib.error.NotFoundError:
ev = None ev = None
if ev: if ev:
icev = Calendar.from_ical(ev.data) icev = Calendar.from_ical(ev.data).subcomponents[1]
ex = True ex = True
if icev.subcomponents[1]['summary'] != self.event['summary']: if icev['summary'] != self.event['summary']:
ex = False ex = False
else: else:
for key in ['dtstart', 'dtend']: for key in ['dtstart', 'dtend']:
if icev.subcomponents[1][key].to_ical() != self.event[key].to_ical(): if icev[key].to_ical() != self.event[key].to_ical():
ex = False ex = False
if ex: return if ex: return
print(f'Change on {self.event.decoded("dtstart").isoformat()}') print(f'Change on {self.event.decoded("dtstart").isoformat()}')
@ -125,6 +125,12 @@ class GoogleSheetsCalParser(HTMLParser):
mr[1] -= 1 mr[1] -= 1
elif tag == 'tbody': elif tag == 'tbody':
self.inTable = False self.inTable = False
for ev in self.calendar.events():
icev = Calendar.from_ical(ev.data).subcomponents[1]
if icev['uid'] not in self.uids:
ev.delete()
print(f'Deleted event on {icev.decoded("dtstart").isoformat()}')
def handle_data(self, data): def handle_data(self, data):
if self.inDate: if self.inDate: