-
Notifications
You must be signed in to change notification settings - Fork 0
/
LightBoxHost.py
46 lines (32 loc) · 1.63 KB
/
LightBoxHost.py
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
#!/usr/bin/env python3
from datetime import datetime, timedelta, time #Timestamps
from multiprocessing import Process, log_to_stderr, set_start_method #Multiprocessing functions for handling ReminderHost
import json #Json Serialisation
import logging #Error routing
import ReminderHost #ReminderHost class
from time import sleep #Thread blocking
import atexit
import sys
class LightBoxHost:
"""
The root of the program, responsible for cycling the instance of ReminderHost at the start of every day
"""
def __init__(self):
log_to_stderr(logging.CRITICAL)
#Load reminder configuration
config = json.load(open("MedicationInfo.json", "r"))
remHost = None
while True:
now = datetime.now() #Get current time and date
#Launch ReminderHost
remHost = Process(name="ReminderHost", target=ReminderHost.ReminderHost, args=(config,))
remHost.start()
sys.stdin.flush()
#Calculate seconds until next day
tomorrow = now + timedelta(days=1)
countdown = (datetime.combine(tomorrow, time.min) - now)
print("LightBoxHost: Time until next day: " + str(countdown.total_seconds()) + "s")
#Wait until next day
sleep(countdown.total_seconds())
#Kill reminderhost so we can reopen it
remHost.kill()