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.
87 lines
2.7 KiB
87 lines
2.7 KiB
from dateutil import rrule
|
|
from gcalendar import dateTime
|
|
import datetime
|
|
import pickle
|
|
import json
|
|
import re
|
|
LOCATION = "5500 St Louis Ave, Chicago, IL 60625"
|
|
event = {
|
|
'summary': 'Google I/O 2015',
|
|
'location': '800 Howard St., San Francisco, CA 94103',
|
|
'description': 'A chance to hear more about Google\'s developer products.',
|
|
'start': {
|
|
'dateTime': '2015-05-28T09:00:00-07:00',
|
|
'timeZone': 'America/Los_Angeles',
|
|
},
|
|
'end': {
|
|
'dateTime': '2015-05-28T17:00:00-07:00',
|
|
'timeZone': 'America/Los_Angeles',
|
|
},
|
|
'recurrence': [
|
|
'RRULE:FREQ=DAILY;COUNT=2'
|
|
],
|
|
'attendees': [
|
|
{'email': 'lpage@example.com'},
|
|
{'email': 'sbrin@example.com'},
|
|
],
|
|
'reminders': {
|
|
'useDefault': False,
|
|
'overrides': [
|
|
{'method': 'email', 'minutes': 24 * 60},
|
|
{'method': 'popup', 'minutes': 10},
|
|
],
|
|
},
|
|
}
|
|
|
|
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)
|
|
ret_str = str(ret).split('\n')[-1]
|
|
ret_str=re.sub(r'(UNTIL=[^;]+)',r'\1Z',ret_str)
|
|
return '{}'.format(ret_str)
|
|
|
|
def create_body(class_obj,is_lab = False):
|
|
if not is_lab:
|
|
lab_body = None
|
|
if class_obj.lab:
|
|
lab_body = create_body(class_obj.lab,True)
|
|
|
|
if class_obj.time_range:
|
|
body = {
|
|
# "kind": "calendar#event",
|
|
}
|
|
body['recurrence'] = [rrule_former(class_obj)]
|
|
body['start'] = dateTime(datetime.datetime.combine(class_obj.date_range[0],class_obj.time_range[0]))
|
|
body['end'] = dateTime(datetime.datetime.combine(class_obj.date_range[0],class_obj.time_range[1]))
|
|
body['summary'] = class_obj.title
|
|
body['description'] = 'location: {}'.format(class_obj.location)
|
|
body['location'] = LOCATION
|
|
body['reminders'] = {'useDefault':True}
|
|
if is_lab:
|
|
return body
|
|
else:
|
|
return body,lab_body
|
|
|
|
def json_dump(obj):
|
|
with open('classes.json','w') as file:
|
|
json.dump(obj,file)
|
|
|
|
|
|
def create_event(class_list):
|
|
for class_obj in class_list:
|
|
out = create_body(class_obj)
|
|
if out:
|
|
body,lab_body = out
|
|
yield body
|
|
if lab_body:
|
|
yield lab_body
|
|
if __name__ == "__main__":
|
|
from scraper import get_classes
|
|
with open('schedule.html') as file:
|
|
classes = get_classes(file.read())
|
|
l = list(create_event(classes))
|
|
json_dump(l)
|