This repository has been archived on 2020-10-14. You can view files and clone it, but cannot push or open issues or pull requests.
edt-parser/parser.py

58 lines
1.2 KiB
Python
Executable File

#!/usr/bin/env python
#-*- encoding: utf-8
import sys
import requests
from html.parser import HTMLParser
import caldav, icalendar
# Constants definition
URL = "https://docs.google.com/spreadsheets/u/0/d/e/2PACX-1vQ9yzFLr5mXbIZVK3ucdUZuScAbLoCyPqzHr-5V0aYeCFEz7LuidPdk_EnkkJT-zjemzQQHaKvpeXW2/pubhtml/sheet?headers=false&gid=1619638924"
class GoogleSheetsCalParser(HTMLParser):
"""
Definition of a Google Sheets parser providing a table with each cell
and its position and size
"""
def __init__(self):
self.inTable = False
self.row = 0
self.column = 0
HTMLParser.__init__(self)
def handle_starttag(self, tag, attrs):
if self.inTable:
...
elif tag == 'table':
self.inTable = True
def handle_endtag(self, tag):
...
def handle_data(self, data):
...
# Getting the Google Sheet
try:
r = requests.get(URL)
except ConnectionError as e:
print(e)
sys.exit(1)
if r.status_code != 200:
print(f'Status Code {r.status_code}; could not continue.')
sys.exit(1)
# Parsing the Sheet
calParser = GoogleSheetsCalParser()
calParser.feed(r.text)
# Transforming the cells into events
# Pushing events to caldav server