-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
56 lines (47 loc) · 1.75 KB
/
main.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
51
52
53
54
55
56
import logging
import sys
from logging.handlers import RotatingFileHandler
from PIL import Image, ImageDraw
try:
from rgbmatrix import RGBMatrix
except ModuleNotFoundError: # used for testing
from RGBMatrixEmulator import RGBMatrix
from api.data import Data
from matrix.layout import Layout
from renderer.loading import Loading
from renderer.main import MainRenderer
from utils import led_matrix_options, args
from version import __version__
def main():
print(f'\U0001F3C1 F1-LED-Leaderboard - v{__version__} ({matrix.width}x{matrix.height})')
layout = Layout(matrix.width, matrix.height)
Loading(matrix, canvas, draw, layout)
data = Data()
MainRenderer(matrix, canvas, draw, layout, data)
if __name__ == '__main__':
# Set logging level
if '--debug' in sys.argv:
LOG_LEVEL = logging.DEBUG
sys.argv.remove('--debug')
else:
LOG_LEVEL = logging.WARNING
# Set logger configuration
logger = logging.getLogger('') # root logger
logger.setLevel(LOG_LEVEL)
handler = RotatingFileHandler(filename='f1-led-leaderboard.log',
maxBytes=5 * 1024 * 1024, # 5MB
backupCount=4)
handler.setFormatter(logging.Formatter(fmt='%(asctime)s %(levelname)s: %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p'))
logger.addHandler(handler)
# Initialize the matrix
matrix = RGBMatrix(options=led_matrix_options(args()))
canvas = Image.new('RGB', (matrix.width, matrix.height))
draw = ImageDraw.Draw(canvas)
matrix.SetImage(canvas)
try:
main()
except Exception as e: # For any random unhandled exceptions
logging.exception(SystemExit(e))
finally:
matrix.Clear()