Needs fixing with events that start on middle hours

This commit is contained in:
Edgar P. Burkhart 2020-09-20 23:04:59 +02:00
parent f9d33f7b4e
commit 95c9183bdf
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227

View file

@ -2,6 +2,7 @@
#-*- encoding: utf-8
import sys
from progressbar import progressbar
import requests
from html.parser import HTMLParser
from datetime import datetime as dt, time
@ -40,6 +41,7 @@ class GoogleSheetsCalParser(HTMLParser):
self.inDate = False
self.row = -1
self.column = -1
self.nextCol = -1
self.rowspan = 0
self.date = {}
@ -49,7 +51,7 @@ class GoogleSheetsCalParser(HTMLParser):
password=priv.PASSWORD)
self.calendar = caldav.Calendar(client=client, url=CALURL)
for ev in self.calendar.events():
for ev in progressbar(self.calendar.events()):
ev.delete()
HTMLParser.__init__(self)
@ -60,11 +62,12 @@ class GoogleSheetsCalParser(HTMLParser):
if self.inTable:
if tag == 'tr':
self.row += 1
self.column = -1
self.nextCol = -1
elif tag == 'td':
self.column = self.nextCol
if 'colspan' in dAttrs.keys():
self.column += int(dAttrs['colspan'])
else: self.column += 1
self.nextCol += int(dAttrs['colspan'])
else: self.nextCol += 1
if not (self.row < 3 or (self.row - 2) % 12 < 2):
self.inCell = True
@ -86,6 +89,7 @@ class GoogleSheetsCalParser(HTMLParser):
def handle_data(self, data):
if self.inDate:
self.date[self.column] = dt.strptime(data, '%d-%b-%y').date()
print(self.date[self.column])
elif self.inCell and data not in ['', '-']:
times = [time.fromisoformat(TIMETABLE[(self.row - 2) % 12 - 2][1]),
time.fromisoformat(TIMETABLE[(self.row - 2) % 12 - 2 + self.rowspan][0])]
@ -97,6 +101,7 @@ class GoogleSheetsCalParser(HTMLParser):
event.add('uid', f'{self.row}x{self.column}')
event.add('summary', data)
event.add('dtstamp', dt.now())
print(self.row, self.column, times)
event.add('dtstart', dt.combine(self.date[self.column], times[0],
pytz.timezone('Europe/Paris')))
event.add('dtend', dt.combine(self.date[self.column], times[1],