forked from winstonma/RPi-MagicMirror-Waveshare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·60 lines (44 loc) · 1.39 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
57
58
59
60
#!/usr/bin/python
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import epaper
from configparser import ConfigParser
import logging
from PIL import Image
from io import BytesIO
from time import time, sleep
#logging.basicConfig(level=logging.DEBUG)
try:
# Read config file
config = ConfigParser()
config.read('config.cfg')
refreshRate = config.getint('Display', 'refesh_rate')
model = config.get('Display', 'model')
einkDevice = epaper.epaper(model)
epd = einkDevice.EPD()
epd.init()
epd.Clear()
service = Service('/usr/bin/chromedriver')
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(service=service, options=options)
driver.set_window_size(epd.width, epd.height)
start_url = config.get('MagicMirror', 'address')
driver.get(start_url)
while True:
# Display the screenshot
img = Image.open(BytesIO(driver.get_screenshot_as_png()))
epd.display(epd.getbuffer(img))
sleep(refreshRate - time() % refreshRate)
print('Success')
except IOError as e:
logging.info(e)
except KeyboardInterrupt:
logging.info("ctrl + c:")
epd.init()
epd.Clear()
einkDevice.epdconfig.module_exit()
driver.quit()
exit()