Improve notification

This commit is contained in:
James Jennett-Wheeler 2025-06-24 14:41:45 +01:00
parent 5cd08da0a2
commit fbcf1a8dee

View File

@ -2,7 +2,6 @@ import os
import sys import sys
import traceback import traceback
from datetime import datetime, time from datetime import datetime, time
from sqlite3 import Cursor
import pause import pause
import requests import requests
@ -25,9 +24,9 @@ web_opts.add_argument('--no-sandbox')
web_opts.add_argument('--headless') web_opts.add_argument('--headless')
web_opts.add_argument('--disable-dev-shm-usage') web_opts.add_argument('--disable-dev-shm-usage')
def notify(title, message): def notify(message):
api_url = 'https://hass.jennett-wheeler.co.uk/api/webhook/-Qx6jHsGLHwbBlJpLek5Nj8qS' api_url = 'https://hass.jennett-wheeler.co.uk/api/webhook/-Qx6jHsGLHwbBlJpLek5Nj8qS'
requests.post(api_url, json={"title": title, "message": message}) requests.post(api_url, json={"title": "Monitor Planning", "message": message})
def update_other_applications(): def update_other_applications():
there_were_newly_decided_applications = False there_were_newly_decided_applications = False
@ -63,11 +62,12 @@ def update_other_applications():
print("") print("")
if there_were_newly_decided_applications: if there_were_newly_decided_applications:
notify("New decisions found", f"Council has uploaded {len(weekly_list.new_applications)} new decisions ({chris_decisions} by Chris)") notify(f"Council has uploaded {len(weekly_list.new_applications)} new decisions ({chris_decisions} by Chris)")
return there_were_newly_decided_applications return there_were_newly_decided_applications
if __name__ == '__main__': if __name__ == '__main__':
notify(f"Script Restarted")
try: try:
with sqlite3.connect("./database.db") as connection: with sqlite3.connect("./database.db") as connection:
cursor = connection.cursor() cursor = connection.cursor()
@ -82,7 +82,7 @@ if __name__ == '__main__':
application.scrape_portal(browser, force=True, count_documents=True) application.scrape_portal(browser, force=True, count_documents=True)
if application.new_documents_found: if application.new_documents_found:
notify("New Documents Found", f"Application now has {application.num_documents} documents") notify(f"New Documents Found: Application now has {application.num_documents} documents")
print("") print("")
if is_working_hours(): if is_working_hours():
@ -120,7 +120,7 @@ if __name__ == '__main__':
except Exception as e: except Exception as e:
print(f'Error found: {repr(e)}') print(f'Error found: {repr(e)}')
print(traceback.format_exc()) print(traceback.format_exc())
notify("Error in planning monitor", repr(e)) notify(f"Error in planning monitor: {repr(e)}")
try: try:
sys.exit(130) sys.exit(130)