HTTP Request + class init

This commit is contained in:
Edgar P. Burkhart 2020-09-20 21:11:48 +02:00
parent 6c1347f4a8
commit f49d774730
Signed by: edpibu
GPG Key ID: 9833D3C5A25BD227
1 changed files with 26 additions and 1 deletions

View File

@ -1,29 +1,54 @@
#!/usr/bin/env python
#-*- encoding: utf-8
import sys
import requests
from html.parser import HTMLParser
import caldav, icalendar
class GoogleSheetsParser(HTMLParser):
# 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
self.__init__()
def handle_starttag(self, tag, attrs):
print(1)
def handle_endtag(self, tag):
print(1)
def handle_data(self, data):
print(1)
# 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 = GoogleSheetsParser()
calParser.feed(r.text)
# Transforming the cells into events
# Pushing events to caldav server