HTTP Request + class init
This commit is contained in:
parent
6c1347f4a8
commit
f49d774730
1 changed files with 26 additions and 1 deletions
27
parser.py
27
parser.py
|
@ -1,29 +1,54 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
#-*- encoding: utf-8
|
#-*- encoding: utf-8
|
||||||
|
|
||||||
|
import sys
|
||||||
import requests
|
import requests
|
||||||
from html.parser import HTMLParser
|
from html.parser import HTMLParser
|
||||||
import caldav, icalendar
|
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
|
Definition of a Google Sheets parser providing a table with each cell
|
||||||
and its position and size
|
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):
|
def handle_starttag(self, tag, attrs):
|
||||||
|
print(1)
|
||||||
|
|
||||||
def handle_endtag(self, tag):
|
def handle_endtag(self, tag):
|
||||||
|
print(1)
|
||||||
|
|
||||||
def handle_data(self, data):
|
def handle_data(self, data):
|
||||||
|
print(1)
|
||||||
|
|
||||||
|
|
||||||
# Getting the Google Sheet
|
# 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
|
# Parsing the Sheet
|
||||||
calParser = GoogleSheetsParser()
|
calParser = GoogleSheetsParser()
|
||||||
|
calParser.feed(r.text)
|
||||||
|
|
||||||
# Transforming the cells into events
|
# Transforming the cells into events
|
||||||
|
|
||||||
|
|
||||||
# Pushing events to caldav server
|
# Pushing events to caldav server
|
||||||
|
|
||||||
|
|
Reference in a new issue