mirror of
https://codeberg.org/privacy1st/exec-notify
synced 2024-12-24 23:26:04 +01:00
41 lines
871 B
Python
41 lines
871 B
Python
|
#!/usr/bin/env python3
|
||
|
from sys import argv, stderr, stdin
|
||
|
import socket
|
||
|
|
||
|
from de.p1st.exec_notify.lib import exec, config, mail
|
||
|
|
||
|
|
||
|
def main():
|
||
|
"""
|
||
|
echo <body> | ./notify
|
||
|
echo <body> | ./notify <subject>
|
||
|
./notify <subject> <body>
|
||
|
./notify <subject> <body_word_1> <body_word_2> ... <body_word_n>
|
||
|
"""
|
||
|
|
||
|
BODY = None
|
||
|
subj = None
|
||
|
hostname = socket.gethostname()
|
||
|
|
||
|
if len(argv) > 3:
|
||
|
print('execNotify>> Expected at most two arguments!')
|
||
|
exit(1)
|
||
|
if len(argv) == 2 or len(argv) == 3:
|
||
|
subj = argv[1]
|
||
|
if len(argv) == 3:
|
||
|
BODY = argv[2]
|
||
|
|
||
|
if subj is None:
|
||
|
subj = 'notify'
|
||
|
if BODY is None:
|
||
|
BODY = f'=== stdin ===\n{stdin.read()}'
|
||
|
|
||
|
SUBJECT = f'{hostname} | {subj}'
|
||
|
print(BODY)
|
||
|
|
||
|
mail.sendMailOrWriteToFile(SUBJECT=SUBJECT, BODY=BODY)
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
main()
|