now with notify
This commit is contained in:
parent
3d27a0ee04
commit
58d318faee
@ -10,6 +10,7 @@
|
|||||||
service_target_dir: /etc/systemd/system/
|
service_target_dir: /etc/systemd/system/
|
||||||
# adapt to taste
|
# adapt to taste
|
||||||
own_image_percent: 90
|
own_image_percent: 90
|
||||||
|
recipient: "???"
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: Pull the latest version of the code
|
- name: Pull the latest version of the code
|
||||||
|
@ -6,8 +6,11 @@ Type=oneshot
|
|||||||
User={{ ansible_user }}
|
User={{ ansible_user }}
|
||||||
WorkingDirectory={{ code_dest }}
|
WorkingDirectory={{ code_dest }}
|
||||||
ExecStart=python main.py
|
ExecStart=python main.py
|
||||||
Environment="OWN_IMAGE_PERCENT={{ own_image_percent }}"
|
Environment="OWN_IMAGE_PERCENT={{ own_image_percent }}"#
|
||||||
|
Environment="RECIPIENT={{ recipient }}"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
# this ensures that the service is started after the network is up (@reboot)
|
14
src/main.py
14
src/main.py
@ -1,7 +1,9 @@
|
|||||||
import sys
|
import sys
|
||||||
from image_convert import ImageShrink
|
from image_convert import ImageShrink
|
||||||
from get.combined import ImageGetCombined
|
from get.combined import ImageGetCombined
|
||||||
|
from get.template import ImageGetException
|
||||||
from image_show import ImageShow
|
from image_show import ImageShow
|
||||||
|
import notify
|
||||||
|
|
||||||
if len(sys.argv) == 2 and sys.argv[1] == "test":
|
if len(sys.argv) == 2 and sys.argv[1] == "test":
|
||||||
print("Running test")
|
print("Running test")
|
||||||
@ -20,11 +22,21 @@ if "reduce" in sys.argv:
|
|||||||
print("Enabling color reduction")
|
print("Enabling color reduction")
|
||||||
shrink_kwargs["reduce_colors"] = True
|
shrink_kwargs["reduce_colors"] = True
|
||||||
|
|
||||||
|
try:
|
||||||
getter = ImageGetCombined()
|
getter = ImageGetCombined()
|
||||||
converter = ImageShrink(**shrink_kwargs)
|
converter = ImageShrink(**shrink_kwargs)
|
||||||
shower = ImageShow()
|
shower = ImageShow()
|
||||||
|
except Exception as e:
|
||||||
|
print("Failed to initialize")
|
||||||
|
notify.notify_status("Failed to initialize")
|
||||||
|
raise e
|
||||||
|
|
||||||
|
try:
|
||||||
image = getter.get_random_image()
|
image = getter.get_random_image()
|
||||||
image = converter.convert(image)
|
image = converter.convert(image)
|
||||||
shower.show_image(image)
|
shower.show_image(image)
|
||||||
|
notify.notify_status("Success")
|
||||||
|
except ImageGetException as e:
|
||||||
|
print("Failed to get image")
|
||||||
|
notify.notify_status(f"Failed to get image: {e}")
|
||||||
|
raise e
|
26
src/notify.py
Normal file
26
src/notify.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import httpx as h
|
||||||
|
import os
|
||||||
|
import socket
|
||||||
|
|
||||||
|
RECIPIENT = os.getenv("RECIPIENT", "DEV")
|
||||||
|
|
||||||
|
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
|
||||||
|
s.connect(('8.8.8.8', 80))
|
||||||
|
(addr, port) = s.getsockname()
|
||||||
|
IPS = addr
|
||||||
|
|
||||||
|
def notify_status(status):
|
||||||
|
data = f"Status: {status}\nIP: {IPS}"
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Title" : f"Eink - {RECIPIENT}",
|
||||||
|
# "Click": "https://home.nest.com/",
|
||||||
|
# "Attach": "https://nest.com/view/yAxkasd.jpg",
|
||||||
|
# "Actions": "http, Open door, https://api.nest.com/open/yAxkasd, clear=true",
|
||||||
|
# "Email": "phil@example.com"
|
||||||
|
}
|
||||||
|
h.post(
|
||||||
|
"https://ntfy.kluster.moll.re/eink",
|
||||||
|
data=data,
|
||||||
|
headers=headers
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user