python-zulip-api/zulip/zulip/examples/alert-words
Anders Kaseorg e30b3b094b Modernize legacy Python 2 syntax with pyupgrade.
Generated by `pyupgrade --py3-plus --keep-percent-format` followed by
manual indentation fixes.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-18 15:04:36 -07:00

31 lines
752 B
Python
Executable file

#!/usr/bin/env python3
import argparse
import zulip
usage = """alert-words (get | add | remove) [words] [options]
Example: alert-words get
Example: alert-words add foo bar
Example: alert-words remove banana
"""
parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
parser.add_argument('operation', choices=['get', 'add', 'remove'], type=str)
parser.add_argument('words', type=str, nargs='*')
options = parser.parse_args()
client = zulip.init_from_options(options)
if options.operation == 'get':
result = client.get_alert_words()
elif options.operation == 'add':
result = client.add_alert_words(options.words)
elif options.operation == 'remove':
result = client.remove_alert_words(options.words)
print(result)