-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlec_scheduler.py
More file actions
66 lines (51 loc) · 1.64 KB
/
lec_scheduler.py
File metadata and controls
66 lines (51 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
'''
lec_scheduler.py:
reads the stored calendar and schedule capturing tasks;
also kick off the calendar receiver route
will stay awake all time.
'''
import json
import os
import signal
import sched
import pytz
import time
from datetime import datetime, timedelta
import utils
import cal_receiver
import Monitor
def signal_handler(signal, frame):
'''Force quit when detected Ctrl+C'''
print('Exiting...')
os._exit(0)
signal.signal(signal.SIGINT, signal_handler)
def schedule_lectures(ics_path, func):
'''read ICS from @ics_path and schedule @func at given time'''
utils.log('INFO', 'Starting scheduling capturing...')
gcal = utils.get_cal(ics_path)
utils.print_cal_events(gcal)
Monitor.FUNC = func
# initialize scheduler for events
Monitor.SCHED = sched.scheduler(time.time, time.sleep)
for component in gcal.walk():
if component.name == "VEVENT":
summary = component.get('summary')
start_time = component.get('dtstart').dt
end_time = component.get('dtend').dt
time_delta = end_time - start_time
seconds = time_delta.total_seconds()
args = summary.split(' ')
args.append(seconds)
# create new Monitor
if start_time < utils.utc_now():
continue
job = Monitor.Monitor(Monitor.SCHED, func, args, start_time)
Monitor.MONITORS.append(job)
# Schedule all events
for mo in Monitor.MONITORS:
mo.schedule_task()
utils.log('INFO', 'Finished scheduling capturing...')
cal_receiver.start_server()
while 1:
pass