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.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:
|
||||||
|
|
Reference in a new issue