File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -92,23 +92,31 @@ def _send_file(
92
92
@beartype
93
93
def main (
94
94
topic : str ,
95
+ message : str = None ,
95
96
render_md : bool = False ,
96
97
) -> None :
97
98
"""
98
99
Main function to process a URL or file type and URL, generate a summary, and send it as a notification.
99
100
100
101
Args:
101
102
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.
102
104
render_md (bool, False by default): True to pass the md string into rich for rendering before sending to ntfy
103
105
104
106
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.
106
108
Exception: For any errors that occur during processing.
107
109
"""
108
110
log (f"Started with topic: '{ topic } '. Version: { VERSION } " )
109
111
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" ]
112
120
log (f"Message: { message } " )
113
121
sn = partial (
114
122
_send_notif ,
You can’t perform that action at this time.
0 commit comments