diff --git a/.gitignore b/.gitignore index 15c7049..82d60ea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.pkl +*.json __pycache__ -/api_info \ No newline at end of file +/api_info diff --git a/body_create.py b/body_create.py index e85eae6..77cffc8 100644 --- a/body_create.py +++ b/body_create.py @@ -1,6 +1,9 @@ from dateutil import rrule +from gcalendar import dateTime import datetime import pickle +import json +LOCATION = "5500 St Louis Ave, Chicago, IL 60625" # event = { # 'summary': 'Google I/O 2015', # 'location': '800 Howard St., San Francisco, CA 94103', @@ -34,13 +37,22 @@ def rrule_former(class_obj): 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 = list(map(lambda day: (day -1) % 7,days)) + 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 +def create_body(_class): + if _class.time_range: + body = {} + body['recurrence'] = [str(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['summary'] = _class.title + body['description'] = 'location: {}'.format(_class.location) + body['location'] = LOCATION + return body - -def test(): +def test_rrule(): #test now = datetime.datetime.now() from munch import Munch @@ -56,4 +68,10 @@ def test(): ], ) test_result = rrule_former(test_obj) - return locals() \ No newline at end of file + return locals() + +def test_class2body(): + with open('classes.pkl','rb') as file: + classes = pickle.load(file) + test_result = list(map(create_body,classes)) + return test_result \ No newline at end of file