python-zulip-api/zulip/zulip/examples/edit-stream
PIG208 9ce7c52a10 pyupgrade: Reformat with --py36-plus.
This includes mainly fixes of string literals using f-strings or
.format(...), as well as unpacking of list comprehensions.
2021-06-02 18:45:57 -07:00

44 lines
1.3 KiB
Python
Executable file

#!/usr/bin/env python3
import argparse
import zulip
usage = """edit-stream --stream-id <stream_id>
[--description <new_description> --new-name <new_name>
--private --announcement-only --history-public-to-subscribers]
Example: edit-stream --stream-id=42 --description="A city in Italy." \
--new-name="Verona" --private
Example: edit-stream --stream-id=3 --history-public-to-subscribers
"""
def quote(string: str) -> str:
return f'"{string}"'
parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
parser.add_argument("--stream-id", type=int, required=True)
parser.add_argument("--description")
parser.add_argument("--new-name")
parser.add_argument("--private", action="store_true")
parser.add_argument("--announcement-only", action="store_true")
parser.add_argument("--history-public-to-subscribers", action="store_true")
options = parser.parse_args()
client = zulip.init_from_options(options)
print(
client.update_stream(
{
"stream_id": options.stream_id,
"description": quote(options.description),
"new_name": quote(options.new_name),
"is_private": options.private,
"is_announcement_only": options.announcement_only,
"history_public_to_subscribers": options.history_public_to_subscribers,
}
)
)