Skip to content

Commit 5fce135

Browse files
minor: add another way to launch the script to make it easier to debug
1 parent 70e53d9 commit 5fce135

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

scripts/NtfySummarizer/NtfySummarizer.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,31 @@ def _send_file(
9292
@beartype
9393
def main(
9494
topic: str,
95+
message: str = None,
9596
render_md: bool = False,
9697
) -> None:
9798
"""
9899
Main function to process a URL or file type and URL, generate a summary, and send it as a notification.
99100
100101
Args:
101102
topic (str): The ntfy.sh topic to send the notification to.
103+
message (str, optional): The message to process. If not provided, will use NTFY_MESSAGE env var.
102104
render_md (bool, False by default): True to pass the md string into rich for rendering before sending to ntfy
103105
104106
Raises:
105-
AssertionError: If NTFY_MESSAGE is not in os.environ, or if the message format is incorrect.
107+
AssertionError: If neither message argument nor NTFY_MESSAGE env var is available, or if the message format is incorrect.
106108
Exception: For any errors that occur during processing.
107109
"""
108110
log(f"Started with topic: '{topic}'. Version: {VERSION}")
109111
topic = topic.strip()
110-
assert "NTFY_MESSAGE" in os.environ, "missing NTFY_MESSAGE in os.environ"
111-
message: str = os.environ["NTFY_MESSAGE"]
112+
113+
# Try env var first, fall back to argument
114+
if message is None:
115+
if "NTFY_MESSAGE" not in os.environ:
116+
raise ValueError(
117+
"No message provided: need either --message argument or NTFY_MESSAGE environment variable"
118+
)
119+
message = os.environ["NTFY_MESSAGE"]
112120
log(f"Message: {message}")
113121
sn = partial(
114122
_send_notif,

0 commit comments

Comments
 (0)