Fixed deletion of removed events
This commit is contained in:
parent
2857556170
commit
fd2219ca8c
1 changed files with 11 additions and 5 deletions
16
parser.py
16
parser.py
|
@ -48,6 +48,7 @@ class GoogleSheetsCalParser(HTMLParser):
|
|||
self.date = {}
|
||||
self.event = Event()
|
||||
self.event['uid'] = 0
|
||||
self.uids = []
|
||||
|
||||
import priv
|
||||
|
||||
|
@ -56,8 +57,6 @@ class GoogleSheetsCalParser(HTMLParser):
|
|||
self.calendar = caldav.Calendar(client=client, url=CALURL)
|
||||
|
||||
#print(self.calendar.event_by_uid('42x26').data)
|
||||
#for ev in progressbar(self.calendar.events()):
|
||||
# print(ev.url, ev.canonical_url())
|
||||
|
||||
HTMLParser.__init__(self)
|
||||
|
||||
|
@ -99,18 +98,19 @@ class GoogleSheetsCalParser(HTMLParser):
|
|||
cal.add('version', '2.0')
|
||||
cal.add_component(self.event)
|
||||
|
||||
self.uids.append(self.event['uid'])
|
||||
try:
|
||||
ev = self.calendar.event_by_uid(self.event['uid'])
|
||||
except caldav.lib.error.NotFoundError:
|
||||
ev = None
|
||||
if ev:
|
||||
icev = Calendar.from_ical(ev.data)
|
||||
icev = Calendar.from_ical(ev.data).subcomponents[1]
|
||||
ex = True
|
||||
if icev.subcomponents[1]['summary'] != self.event['summary']:
|
||||
if icev['summary'] != self.event['summary']:
|
||||
ex = False
|
||||
else:
|
||||
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
|
||||
if ex: return
|
||||
print(f'Change on {self.event.decoded("dtstart").isoformat()}')
|
||||
|
@ -125,6 +125,12 @@ class GoogleSheetsCalParser(HTMLParser):
|
|||
mr[1] -= 1
|
||||
elif tag == 'tbody':
|
||||
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):
|
||||
if self.inDate:
|
||||
|
|
Reference in a new issue