-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.py
50 lines (39 loc) · 1.89 KB
/
server.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
47
48
49
50
import eel, time, exchange, os
from apscheduler.schedulers.background import BackgroundScheduler
# Initiates the web folder in the hierarchy.
eel.init('web')
# A function that triggers a JavaScript function that navigates to today in the calendar view.
def nextDayPython():
eel.nextDay()
# Get updated calendar information from Exchange every 5 seconds.
def getExchangeEventsThread():
while True:
exchange.calendarIteration()
eel.sleep(5.0)
# Check for room availability by comparing the current time to the list of busy times (busyTimesFlat).
# This is run after waiting 5 seconds for the calendar information to be updated and then every 5 seconds after.
def roomAvailabilityThread():
while True:
eel.sleep(5.0)
exchange.roomAvailability()
# Set up a scheduled event that runs nextDayPython daily at 5am.
def nextDayThread():
scheduler = BackgroundScheduler()
scheduler.add_job(nextDayPython, 'cron', hour=5, minute=0)
scheduler.start()
# Starts the function to get updated calendar information in its own thread.
eel.spawn(getExchangeEventsThread)
# Starts the function to check room availability in its own thread.
eel.spawn(roomAvailabilityThread)
# Starts the function to navigate to today in the calendar view in its own thread.
eel.spawn(nextDayThread)
# Settings to run Chrome in kiosk mode if eel.start is run with the web_app_options.
web_app_options = {
'mode': 'chrome-app',
'chromeFlags': ['--kiosk']
}
# Because of Raspberry Pi's modest hardware, a 2 second delay is added
# to make sure the needed information is collected from Exchange before running.
eel.sleep(2)
# eel.start('main.html', size=(800, 480)) # Uncomment this for the application to run in a broswer window.
# eel.start('main.html', options=web_app_options) # Uncomment this for the application to run in Chrome's kiosk mode.