You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.5 KiB
50 lines
1.5 KiB
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)
|
|
classes = []
|
|
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,
|
|
)
|
|
|
|
classes.append(e)
|
|
for _class in classes:
|
|
school_calendar.update_or_add_event(_class)
|