From 61e0002d2c4b209721027f7992b1c10dafe654d7 Mon Sep 17 00:00:00 2001 From: Raphael Roberts Date: Wed, 8 Jan 2020 11:24:14 -0600 Subject: [PATCH] Added function to convert Class objects to Event objects. --- .gitignore | 3 ++- upload.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 upload.py diff --git a/.gitignore b/.gitignore index 591cbc3..6ecdb39 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ __pycache__ /api_info *.html -.dir-locals.el \ No newline at end of file +.dir-locals.el +*.whl diff --git a/upload.py b/upload.py new file mode 100644 index 0000000..90dddaa --- /dev/null +++ b/upload.py @@ -0,0 +1,47 @@ +import datetime + +from dateutil import rrule +from gapi.apis.calendar_api import get_calendars_from_api, calendar_api +from gapi.apis.calendar_api.models import Event + +from scraper import get_classes, Class + +LOCATION = "5500 St Louis Ave, Chicago, IL 60625" + + +def rrule_former(class_obj): + days = class_obj.days + start = datetime.datetime.combine( + class_obj.date_range[0], class_obj.time_range[0] + ).astimezone() + end = datetime.datetime.combine( + class_obj.date_range[1], class_obj.time_range[1] + ).astimezone() + + days = [(day - 1) % 7 for day in days] + ret = rrule.rrule( + freq=rrule.WEEKLY, dtstart=start, wkst=rrule.SU, until=end, byweekday=days + ) + return ret + + +if __name__ == "__main__": + with open("schedule.html", "rb") as file: + data = file.read() + _class: Class + my_api = calendar_api( + "Class upload", scopes=["https://www.googleapis.com/auth/calendar"] + ) + calendars = get_calendars_from_api(my_api) + l = [] + for _class in get_classes(data): + if _class.time_range is not None: + e = Event( + datetime.datetime.combine(_class.date_range[0], _class.time_range[0]), + datetime.datetime.combine(_class.date_range[0], _class.time_range[1]), + _class.title, + "location: {}".format(_class.location), + rrule_former(_class), + location=LOCATION, + ) + l.append(e)