forked from speedyg0nz/MagInkDash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
70 lines (60 loc) · 2.78 KB
/
main.py
File metadata and controls
70 lines (60 loc) · 2.78 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
67
68
69
70
"""
This project is designed for the Inkplate 10 display. However, since the server code is only generating an image, it can
be easily adapted to other display sizes and resolution by adjusting the config settings, HTML template and
CSS stylesheet.
As a dashboard, there are many other things that could be displayed, and it can be done as long as you are able to
retrieve the information. So feel free to change up the code and amend it to your needs.
"""
import datetime
import logging
import sys
import json
import os
from datetime import datetime as dt
from pytz import timezone
from gcal.gcal import GcalModule
from render.render import RenderHelper
if __name__ == '__main__':
logger = logging.getLogger('maginkdash')
# Basic configuration settings (user replaceable)
configFile = open('config.json')
config = json.load(configFile)
calendars = config['calendars'] # Google Calendar IDs
ignorePatterns = config.get('ignorePatterns', []) # Regex patterns for events to ignore
displayTZ = timezone(config['displayTZ']) # list of timezones - print(pytz.all_timezones)
imageWidth = config['imageWidth'] # Width of image to be generated for display.
imageHeight = config['imageHeight'] # Height of image to be generated for display.
timeFormat = config.get('timeFormat', 12) # 12 or 24-hour time format, default to 12 if not specified
path_to_server_image = config["path_to_server_image"] # Location to save the generated image
# Create and configure logger
logging.basicConfig(filename="logfile.log", format='%(asctime)s %(levelname)s - %(message)s', filemode='a')
logger = logging.getLogger('maginkdash')
logger.addHandler(logging.StreamHandler(sys.stdout)) # print logger to stdout
logger.setLevel(logging.INFO)
logger.info("Starting dashboard update")
logger.info(f"Using {'24' if timeFormat == 24 else '12'}-hour time format")
# Retrieve Calendar Data - get up to 3 days
currDate = dt.now(displayTZ).date()
calStartDatetime = displayTZ.localize(dt.combine(currDate, dt.min.time()))
calEndDatetime = displayTZ.localize(dt.combine(currDate + datetime.timedelta(days=2), dt.max.time()))
calModule = GcalModule()
allEventList = calModule.get_events(
currDate,
calendars,
calStartDatetime,
calEndDatetime,
displayTZ,
3,
)
# Render Dashboard Image
renderService = RenderHelper(imageWidth, imageHeight, timeFormat)
renderService.process_inputs(
currDate,
allEventList,
path_to_server_image,
ignorePatterns,
)
# Get absolute path to the generated image
absolute_image_path = os.path.abspath(path_to_server_image)
logger.info(f"Dashboard image saved to: {absolute_image_path}")
logger.info("Completed dashboard update")