Add device-bound robot notifications and automatic OAuth cards
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
"""Explicit local notification CLI; never accepts a recipient or arbitrary card JSON."""
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
from .work_client import WorkClient, WorkError
|
||||
from .notification_client import push
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--directory', type=Path, required=True)
|
||||
parser.add_argument('--url', required=True)
|
||||
parser.add_argument('--request-id', required=True)
|
||||
parser.add_argument('--kind', choices=['text', 'notice', 'authorization'], default='text')
|
||||
parser.add_argument('--text', default='')
|
||||
parser.add_argument('--title', default='')
|
||||
args = parser.parse_args()
|
||||
client = WorkClient(args.directory, args.url)
|
||||
try:
|
||||
if args.kind == 'authorization':
|
||||
client.authorize() # Auto-pushes once; claim secret and OAuth URL are not printed.
|
||||
result = {'status': client.read(client.pending).get('notification_status', 'unknown')}
|
||||
else:
|
||||
result = push(client, request_id=args.request_id, kind=args.kind,
|
||||
text=args.text, title=args.title)
|
||||
print(json.dumps(result, ensure_ascii=False))
|
||||
except WorkError as error:
|
||||
parser.exit(1, str(error) + '\n')
|
||||
finally:
|
||||
client.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user