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 traceback
from datetime import datetime, time
from sqlite3 import Cursor
import pause
import requests
@ -25,9 +24,9 @@ web_opts.add_argument('--no-sandbox')
web_opts.add_argument('--headless')
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'
requests.post(api_url, json={"title": title, "message": message})
requests.post(api_url, json={"title": "Monitor Planning", "message": message})
def update_other_applications():
there_were_newly_decided_applications = False
@ -63,11 +62,12 @@ def update_other_applications():
print("")
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
if __name__ == '__main__':
notify(f"Script Restarted")
try:
with sqlite3.connect("./database.db") as connection:
cursor = connection.cursor()
@ -82,7 +82,7 @@ if __name__ == '__main__':
application.scrape_portal(browser, force=True, count_documents=True)
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("")
if is_working_hours():
@ -120,7 +120,7 @@ if __name__ == '__main__':
except Exception as e:
print(f'Error found: {repr(e)}')
print(traceback.format_exc())
notify("Error in planning monitor", repr(e))
notify(f"Error in planning monitor: {repr(e)}")
try:
sys.exit(130)