From 27abec997b61edb160a0ca02d93b0732603bd084 Mon Sep 17 00:00:00 2001 From: Peter Pugno Date: Tue, 28 Apr 2026 01:20:50 +1000 Subject: [PATCH] Add debug logging and fix port=None for HTTPS URLs Co-Authored-By: Claude --- notify.py | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/notify.py b/notify.py index 64b3e78..9fef833 100644 --- a/notify.py +++ b/notify.py @@ -1,5 +1,6 @@ import os import ast +import sys import socket import requests import schedule @@ -143,6 +144,10 @@ def check_and_notify(): if item['monitored']: monitored_albums.append(item) + print(f'Monitoring {len(monitored_albums)} album(s) out of {len(users_shared_albums)} total') + else: + print(f'Album file not found: {albums_file_path}') + if os.path.exists(albums_file_path): config = load_data(config_file_path) IMMICH_API_KEY = config['Immich API Key'] @@ -154,8 +159,14 @@ def check_and_notify(): NTFY_EMAIL_TAG = config['ntfy Email Tag'] AUTHORIZATION_KEY = config['ntfy Authorization'] url = urlparse(BASE_URL) + if DEBUG: + print(f'Config loaded — Immich: {BASE_URL}, ntfy: {NTFY_URL}') - if check(url.hostname, url.port): + port = url.port or (443 if url.scheme == 'https' else 80) + + print(f'Connecting to {url.hostname}:{port} ...') + if check(url.hostname, port): + print('Connection successful') if os.path.exists(data_file_path): if DEBUG: print('File Exists') @@ -224,31 +235,48 @@ def check_and_notify(): else: message = 'Photo added to ' + a['albumName'] + '!' + print(f'Sending notification to {url}: "{message}"') ntfy_notification(url, title, message, link, NTFY_ICON, AUTHORIZATION_KEY) + print('Notification sent') if EMAIL != '': topic = a['topic'] + '_email' url = NTFY_URL + '/' + topic message = 'Immich - ' + message + ' ' + link + print(f'Sending email notification to {url} -> {EMAIL}') ntfy_email(url, message, EMAIL, NTFY_EMAIL_TAG, AUTHORIZATION_KEY) + print('Email notification sent') + else: + if DEBUG: + print(f'No new items in "{a["albumName"]}"') stored_albums = updated_stored_albums else: + print('First run — recording current album counts (no notification sent)') for key in monitored_albums: album_id = key['id'] total_items = get_album_contents(BASE_URL, album_id, IMMICH_API_KEY) key['stored items'] = total_items - if DEBUG: - print('Album Name:', key['albumName']) - print('Total Items Now: ', total_items) + print(f' "{key["albumName"]}": {total_items} item(s)') stored_albums = monitored_albums write_data(data_file_path, stored_albums) + else: + print(f'Connection to {url.hostname}:{port} failed — skipping this run') + +if '--test' in sys.argv: + print('--- TEST RUN ---') + if os.path.exists(app_file_path): + app_vars = load_data(app_file_path) + check_and_notify() + else: + print(f'No App Config JSON file at {app_file_path}') + sys.exit(0) stored_time = "0" stored_enable = '' @@ -271,4 +299,4 @@ def check_and_notify(): stored_time = SCHEDULE_TIME else: print('No App Config JSON file at ', app_file_path) - time.sleep(1) + time.sleep(1) \ No newline at end of file