|
|
|
@ -3,34 +3,35 @@ 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}, |
|
|
|
# ], |
|
|
|
# }, |
|
|
|
# } |
|
|
|
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 |
|
|
|
@ -39,19 +40,25 @@ def rrule_former(class_obj): |
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
ret_str = str(ret).split('\n')[-1] |
|
|
|
ret_str=re.sub(r'(UNTIL=[^;]+)',r'\1Z',ret_str) |
|
|
|
return 'RRULE:{}'.format(ret_str) |
|
|
|
def create_body(_class): |
|
|
|
if _class.time_range: |
|
|
|
body = {} |
|
|
|
body['recurrence'] = [str(rrule_former(_class))] |
|
|
|
body = { |
|
|
|
# "kind": "calendar#event", |
|
|
|
} |
|
|
|
body['recurrence'] = [rrule_former(_class)] |
|
|
|
body['start'] = dateTime(datetime.datetime.combine(_class.date_range[0],_class.time_range[0])) |
|
|
|
body['end'] = dateTime(datetime.datetime.combine(_class.date_range[1],_class.time_range[0])) |
|
|
|
body['end'] = dateTime(datetime.datetime.combine(_class.date_range[0],_class.time_range[1])) |
|
|
|
body['summary'] = _class.title |
|
|
|
body['description'] = 'location: {}'.format(_class.location) |
|
|
|
body['location'] = LOCATION |
|
|
|
body['reminders'] = {'useDefault':True} |
|
|
|
return body |
|
|
|
|
|
|
|
def json_dump(obj): |
|
|
|
with open('classes.json','w') as file: |
|
|
|
json.dump(obj,file) |
|
|
|
def test_rrule(): |
|
|
|
#test |
|
|
|
now = datetime.datetime.now() |
|
|
|
@ -73,5 +80,8 @@ def test_rrule(): |
|
|
|
def test_class2body(): |
|
|
|
with open('classes.pkl','rb') as file: |
|
|
|
classes = pickle.load(file) |
|
|
|
test_result = list(map(create_body,classes)) |
|
|
|
return test_result |
|
|
|
test_result = list(filter(bool,map(create_body,classes))) |
|
|
|
return test_result |
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
json_dump(test_class2body()) |