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.

76 lines
2.4 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. from dateutil import rrule
  2. from gcalendar import dateTime
  3. import datetime
  4. import pickle
  5. import json
  6. LOCATION = "5500 St Louis Ave, Chicago, IL 60625"
  7. # event = {
  8. # 'summary': 'Google I/O 2015',
  9. # 'location': '800 Howard St., San Francisco, CA 94103',
  10. # 'description': 'A chance to hear more about Google\'s developer products.',
  11. # 'start': {
  12. # 'dateTime': '2015-05-28T09:00:00-07:00',
  13. # 'timeZone': 'America/Los_Angeles',
  14. # },
  15. # 'end': {
  16. # 'dateTime': '2015-05-28T17:00:00-07:00',
  17. # 'timeZone': 'America/Los_Angeles',
  18. # },
  19. # 'recurrence': [
  20. # 'RRULE:FREQ=DAILY;COUNT=2'
  21. # ],
  22. # 'attendees': [
  23. # {'email': 'lpage@example.com'},
  24. # {'email': 'sbrin@example.com'},
  25. # ],
  26. # 'reminders': {
  27. # 'useDefault': False,
  28. # 'overrides': [
  29. # {'method': 'email', 'minutes': 24 * 60},
  30. # {'method': 'popup', 'minutes': 10},
  31. # ],
  32. # },
  33. # }
  34. def rrule_former(class_obj):
  35. days = class_obj.days
  36. start =datetime.datetime.combine(class_obj.date_range[0],class_obj.time_range[0]).astimezone()
  37. end =datetime.datetime.combine(class_obj.date_range[1],class_obj.time_range[1]).astimezone()
  38. days = [ (day -1) % 7 for day in days]
  39. ret = rrule.rrule(freq=rrule.WEEKLY,dtstart=start,wkst=rrule.SU,until=end,byweekday=days)
  40. return ret
  41. def create_body(_class):
  42. if _class.time_range:
  43. body = {}
  44. body['recurrence'] = [str(rrule_former(_class))]
  45. body['start'] = dateTime(datetime.datetime.combine(_class.date_range[0],_class.time_range[0]))
  46. body['end'] = dateTime(datetime.datetime.combine(_class.date_range[1],_class.time_range[0]))
  47. body['summary'] = _class.title
  48. body['description'] = 'location: {}'.format(_class.location)
  49. body['location'] = LOCATION
  50. return body
  51. def test_rrule():
  52. #test
  53. now = datetime.datetime.now()
  54. from munch import Munch
  55. test_obj = Munch(
  56. days=[1,3,5],
  57. time_range=[
  58. now.time(),
  59. (now+datetime.timedelta(seconds=50*60)).time()
  60. ],
  61. date_range=[
  62. now.date(),
  63. (now+datetime.timedelta(days=20)).date()
  64. ],
  65. )
  66. test_result = rrule_former(test_obj)
  67. return locals()
  68. def test_class2body():
  69. with open('classes.pkl','rb') as file:
  70. classes = pickle.load(file)
  71. test_result = list(map(create_body,classes))
  72. return test_result