Added dates

This commit is contained in:
Edgar P. Burkhart 2020-09-20 21:51:41 +02:00
parent 27ee15ba2d
commit 00be0b5ff4
Signed by: edpibu
GPG Key ID: 9833D3C5A25BD227
1 changed files with 22 additions and 3 deletions

View File

@ -4,6 +4,7 @@
import sys
import requests
from html.parser import HTMLParser
from datetime import datetime as dt
import caldav, icalendar
@ -32,30 +33,48 @@ class GoogleSheetsCalParser(HTMLParser):
def __init__(self):
self.inTable = False
self.inCell = False
self.inDate = False
self.row = -1
self.column = -1
self.rowspan = 0
self.date = 0
HTMLParser.__init__(self)
def handle_starttag(self, tag, attrs):
dAttrs = dict(attrs)
if self.inTable:
if tag == 'tr':
self.row += 1
self.column = -1
elif tag == 'td':
self.column += 1
if not (self.row < 3 or (self.row - 2) % 11 < 2):
if 'colspan' in dAttrs.keys():
self.column += int(dAttrs['colspan'])
else: self.column += 1
if not (self.row < 3 or (self.row - 2) % 12 < 2):
self.inCell = True
if 'rowspan' in dAttrs.keys():
self.rowspan = dAttrs['rowspan']
else: self.rowspan = 1
elif (self.row - 2) % 12 == 1:
self.inDate = True
elif tag == 'tbody':
self.inTable = True
def handle_endtag(self, tag):
if tag == 'td':
self.inCell = False
self.inDate = False
elif tag == 'tbody':
self.inTable = False
def handle_data(self, data):
...
if self.inDate:
self.date = dt.strptime(data, '%d-%b-%y')
print(self.date)
elif self.inCell and data not in ['', '-']:
print(data, self.row, self.column, self.rowspan)
# Getting the Google Sheet