Implementacija obveščanja preko ntfy.sh #12
This commit is contained in:
39
projector.py
39
projector.py
@@ -71,7 +71,9 @@ class SongProjector:
|
||||
"font_bold": True,
|
||||
"show_song_info": True,
|
||||
"split_by_stanza": False, # TODO: mogoče nekoč (prelom po kitici namesto po višini)
|
||||
"db_update_url": ""
|
||||
"db_update_url": "",
|
||||
"ntfy_topic": "",
|
||||
"installation_label": "Projekcija: DEFAULT"
|
||||
}
|
||||
|
||||
if not os.path.exists(SETTINGS_PATH):
|
||||
@@ -633,6 +635,41 @@ class SongProjector:
|
||||
subprocess.Popen(args)
|
||||
|
||||
self.root.after(200, self.exit_program)
|
||||
|
||||
# ------------------------------------------------------
|
||||
# Pošiljanje ntfy obvestil
|
||||
# ------------------------------------------------------
|
||||
def send_ntfy_notification(self, song_id, title, lyrics):
|
||||
"""
|
||||
Pošlje obvestilo o spremembi besedila preko ntfy.sh.
|
||||
"""
|
||||
topic = self.settings.get("ntfy_topic", "").strip()
|
||||
if not topic:
|
||||
return
|
||||
|
||||
label = self.settings.get("installation_label", "Projekcija")
|
||||
# ntfy.sh headers must be ASCII. We'll use base64 encoding for the title to support non-ASCII characters.
|
||||
import base64
|
||||
encoded_label = "=?UTF-8?B?" + base64.b64encode(label.encode('utf-8')).decode('utf-8') + "?="
|
||||
|
||||
message = f"{song_id}\n{title}\n{lyrics}"
|
||||
|
||||
try:
|
||||
url = f"https://ntfy.sh/{topic}"
|
||||
req = urllib.request.Request(
|
||||
url,
|
||||
data=message.encode('utf-8'),
|
||||
method='POST',
|
||||
headers={ "Title": encoded_label,
|
||||
"Priority": "high",
|
||||
"Tags": "loudspeaker" }
|
||||
)
|
||||
# Uporabimo kratek timeout, da ne blokiramo aplikacije
|
||||
with urllib.request.urlopen(req, timeout=5) as response:
|
||||
pass
|
||||
except Exception as e:
|
||||
print(f"Napaka pri pošiljanju ntfy obvestila: {e}")
|
||||
|
||||
# ----------------------------------------------------------
|
||||
# Zagon aplikacije
|
||||
# ----------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user