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