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

55 lines
1.1 KiB
Python
Raw Normal View History

2020-09-20 20:53:24 +02:00
#!/usr/bin/env python
#-*- encoding: utf-8
2020-09-20 21:11:48 +02:00
import sys
2020-09-20 20:53:24 +02:00
import requests
from html.parser import HTMLParser
import caldav, icalendar
2020-09-20 21:11:48 +02:00
# 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):
2020-09-20 20:55:27 +02:00
"""
Definition of a Google Sheets parser providing a table with each cell
and its position and size
"""
2020-09-20 21:11:48 +02:00
def __init__(self):
self.inTable = False
self.row = 0
self.column = 0
self.__init__()
2020-09-20 20:53:24 +02:00
def handle_starttag(self, tag, attrs):
2020-09-20 21:11:48 +02:00
print(1)
2020-09-20 20:53:24 +02:00
def handle_endtag(self, tag):
2020-09-20 21:11:48 +02:00
print(1)
2020-09-20 20:53:24 +02:00
def handle_data(self, data):
2020-09-20 21:11:48 +02:00
print(1)
2020-09-20 20:53:24 +02:00
2020-09-20 20:55:27 +02:00
# Getting the Google Sheet
2020-09-20 21:11:48 +02:00
try:
r = requests.get(URL)
except ConnectionError as e:
print(e)
sys.exit(1)
2020-09-20 20:53:24 +02:00
2020-09-20 21:11:48 +02:00
if r.status_code != 200:
print(f'Status Code {r.status_code}; could not continue.')
sys.exit(1)
2020-09-20 20:55:27 +02:00
# Parsing the Sheet
2020-09-20 20:53:24 +02:00
calParser = GoogleSheetsParser()
2020-09-20 21:11:48 +02:00
calParser.feed(r.text)
2020-09-20 20:55:27 +02:00
# Transforming the cells into events
2020-09-20 21:11:48 +02:00
2020-09-20 20:55:27 +02:00
# Pushing events to caldav server
2020-09-20 21:11:48 +02:00