2023-02-22 01:44:27 +00:00
|
|
|
#!/usr/bin/env python
|
2024-02-06 21:06:44 +00:00
|
|
|
from scwrypts import execute
|
|
|
|
#####################################################################
|
2023-02-22 01:44:27 +00:00
|
|
|
from sys import stderr
|
|
|
|
|
2024-02-06 21:06:44 +00:00
|
|
|
from scwrypts.env import getenv
|
|
|
|
from scwrypts.twilio import send_sms
|
|
|
|
|
|
|
|
|
|
|
|
description = 'send a simple SMS through twilio'
|
|
|
|
parse_args = [
|
|
|
|
( ['-t', '--to'], {
|
|
|
|
'dest' : 'to',
|
|
|
|
'help' : 'phone number of the receipient',
|
|
|
|
'required' : False,
|
|
|
|
'default' : getenv('TWILIO__DEFAULT_PHONE_TO', required=False),
|
|
|
|
}),
|
|
|
|
( ['-f', '--from'], {
|
|
|
|
'dest' : 'from_',
|
|
|
|
'help' : 'phone number of the receipient',
|
|
|
|
'required' : False,
|
|
|
|
'default' : getenv('TWILIO__DEFAULT_PHONE_FROM', required=False),
|
|
|
|
}),
|
|
|
|
( ['-b', '--body'], {
|
|
|
|
'dest' : 'body',
|
|
|
|
'help' : 'message body',
|
|
|
|
'required' : False,
|
|
|
|
}),
|
|
|
|
( ['--max-char-count'], {
|
|
|
|
'dest' : 'max_char_count',
|
|
|
|
'help' : 'separate message into parts by character count (1 < N <= 1500)',
|
|
|
|
'required' : False,
|
|
|
|
'default' : 300,
|
|
|
|
}),
|
|
|
|
]
|
2023-02-22 01:44:27 +00:00
|
|
|
|
|
|
|
def main(args, stream):
|
|
|
|
if args.body is None:
|
|
|
|
print(f'reading input from {stream.input.name}', file=stderr)
|
|
|
|
args.body = ''.join(stream.readlines()).strip()
|
|
|
|
|
|
|
|
if len(args.body) == 0:
|
|
|
|
args.body = 'PING'
|
|
|
|
|
|
|
|
if args.from_ is None:
|
|
|
|
raise MissingFlagAndEnvironmentVariableError(['-f', '--from'], 'TWILIO__DEFAULT_PHONE_FROM')
|
|
|
|
|
|
|
|
if args.to is None:
|
|
|
|
raise MissingFlagAndEnvironmentVariableError(['-t', '--to'], 'TWILIO__DEFAULT_PHONE_TO')
|
|
|
|
|
|
|
|
send_sms(
|
|
|
|
to = args.to,
|
|
|
|
from_ = args.from_,
|
|
|
|
body = args.body,
|
|
|
|
max_char_count = args.max_char_count,
|
|
|
|
stream = stream,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
#####################################################################
|
2024-02-06 21:06:44 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
execute(main, description, parse_args)
|