Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions notify.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import ast
import sys
import socket
import requests
import schedule
Expand Down Expand Up @@ -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']
Expand All @@ -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')
Expand Down Expand Up @@ -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 = ''
Expand All @@ -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)