black: Reformat skipping string normalization.
This commit is contained in:
parent
5580c68ae5
commit
fba21bb00d
178 changed files with 6562 additions and 4469 deletions
File diff suppressed because it is too large
Load diff
|
@ -10,19 +10,21 @@ def main() -> None:
|
|||
|
||||
Prints the path to the Zulip API example scripts."""
|
||||
parser = argparse.ArgumentParser(usage=usage)
|
||||
parser.add_argument('script_name',
|
||||
nargs='?',
|
||||
default='',
|
||||
help='print path to the script <script_name>')
|
||||
parser.add_argument(
|
||||
'script_name', nargs='?', default='', help='print path to the script <script_name>'
|
||||
)
|
||||
args = parser.parse_args()
|
||||
zulip_path = os.path.abspath(os.path.dirname(zulip.__file__))
|
||||
examples_path = os.path.abspath(os.path.join(zulip_path, 'examples', args.script_name))
|
||||
if os.path.isdir(examples_path) or (args.script_name and os.path.isfile(examples_path)):
|
||||
print(examples_path)
|
||||
else:
|
||||
raise OSError("Examples cannot be accessed at {}: {} does not exist!"
|
||||
.format(examples_path,
|
||||
"File" if args.script_name else "Directory"))
|
||||
raise OSError(
|
||||
"Examples cannot be accessed at {}: {} does not exist!".format(
|
||||
examples_path, "File" if args.script_name else "Directory"
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -23,9 +23,13 @@ options = parser.parse_args()
|
|||
|
||||
client = zulip.init_from_options(options)
|
||||
|
||||
print(client.create_user({
|
||||
'email': options.new_email,
|
||||
'password': options.new_password,
|
||||
'full_name': options.new_full_name,
|
||||
'short_name': options.new_short_name
|
||||
}))
|
||||
print(
|
||||
client.create_user(
|
||||
{
|
||||
'email': options.new_email,
|
||||
'password': options.new_password,
|
||||
'full_name': options.new_full_name,
|
||||
'short_name': options.new_short_name,
|
||||
}
|
||||
)
|
||||
)
|
||||
|
|
|
@ -29,11 +29,15 @@ 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
|
||||
}))
|
||||
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,
|
||||
}
|
||||
)
|
||||
)
|
||||
|
|
|
@ -15,8 +15,12 @@ Example: get-history --stream announce --topic important"""
|
|||
parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
|
||||
parser.add_argument('--stream', required=True, help="The stream name to get the history")
|
||||
parser.add_argument('--topic', help="The topic name to get the history")
|
||||
parser.add_argument('--filename', default='history.json', help="The file name to store the fetched \
|
||||
history.\n Default 'history.json'")
|
||||
parser.add_argument(
|
||||
'--filename',
|
||||
default='history.json',
|
||||
help="The file name to store the fetched \
|
||||
history.\n Default 'history.json'",
|
||||
)
|
||||
options = parser.parse_args()
|
||||
|
||||
client = zulip.init_from_options(options)
|
||||
|
@ -33,7 +37,7 @@ request = {
|
|||
'num_after': 1000,
|
||||
'narrow': narrow,
|
||||
'client_gravatar': False,
|
||||
'apply_markdown': False
|
||||
'apply_markdown': False,
|
||||
}
|
||||
|
||||
all_messages = [] # type: List[Dict[str, Any]]
|
||||
|
|
|
@ -28,12 +28,16 @@ options = parser.parse_args()
|
|||
|
||||
client = zulip.init_from_options(options)
|
||||
|
||||
print(client.get_messages({
|
||||
'anchor': options.anchor,
|
||||
'use_first_unread_anchor': options.use_first_unread_anchor,
|
||||
'num_before': options.num_before,
|
||||
'num_after': options.num_after,
|
||||
'narrow': options.narrow,
|
||||
'client_gravatar': options.client_gravatar,
|
||||
'apply_markdown': options.apply_markdown
|
||||
}))
|
||||
print(
|
||||
client.get_messages(
|
||||
{
|
||||
'anchor': options.anchor,
|
||||
'use_first_unread_anchor': options.use_first_unread_anchor,
|
||||
'num_before': options.num_before,
|
||||
'num_after': options.num_after,
|
||||
'narrow': options.narrow,
|
||||
'client_gravatar': options.client_gravatar,
|
||||
'apply_markdown': options.apply_markdown,
|
||||
}
|
||||
)
|
||||
)
|
||||
|
|
|
@ -18,13 +18,10 @@ options = parser.parse_args()
|
|||
|
||||
client = zulip.init_from_options(options)
|
||||
|
||||
OPERATIONS = {
|
||||
'mute': 'add',
|
||||
'unmute': 'remove'
|
||||
}
|
||||
OPERATIONS = {'mute': 'add', 'unmute': 'remove'}
|
||||
|
||||
print(client.mute_topic({
|
||||
'op': OPERATIONS[options.op],
|
||||
'stream': options.stream,
|
||||
'topic': options.topic
|
||||
}))
|
||||
print(
|
||||
client.mute_topic(
|
||||
{'op': OPERATIONS[options.op], 'stream': options.stream, 'topic': options.topic}
|
||||
)
|
||||
)
|
||||
|
|
|
@ -19,9 +19,11 @@ options = parser.parse_args()
|
|||
|
||||
client = zulip.init_from_options(options)
|
||||
|
||||
|
||||
def print_event(event: Dict[str, Any]) -> None:
|
||||
print(event)
|
||||
|
||||
|
||||
# This is a blocking call, and will continuously poll for new events
|
||||
# Note also the filter here is messages to the stream Denmark; if you
|
||||
# don't specify event_types it'll print all events.
|
||||
|
|
|
@ -19,8 +19,10 @@ options = parser.parse_args()
|
|||
|
||||
client = zulip.init_from_options(options)
|
||||
|
||||
|
||||
def print_message(message: Dict[str, Any]) -> None:
|
||||
print(message)
|
||||
|
||||
|
||||
# This is a blocking call, and will continuously poll for new messages
|
||||
client.call_on_each_message(print_message)
|
||||
|
|
|
@ -20,5 +20,4 @@ options = parser.parse_args()
|
|||
|
||||
client = zulip.init_from_options(options)
|
||||
|
||||
print(client.add_subscriptions([{"name": stream_name} for stream_name in
|
||||
options.streams.split()]))
|
||||
print(client.add_subscriptions([{"name": stream_name} for stream_name in options.streams.split()]))
|
||||
|
|
|
@ -19,8 +19,8 @@ options = parser.parse_args()
|
|||
|
||||
client = zulip.init_from_options(options)
|
||||
|
||||
print(client.update_message_flags({
|
||||
'op': options.op,
|
||||
'flag': options.flag,
|
||||
'messages': options.messages
|
||||
}))
|
||||
print(
|
||||
client.update_message_flags(
|
||||
{'op': options.op, 'flag': options.flag, 'messages': options.messages}
|
||||
)
|
||||
)
|
||||
|
|
|
@ -10,6 +10,7 @@ import zulip
|
|||
class StringIO(_StringIO):
|
||||
name = '' # https://github.com/python/typeshed/issues/598
|
||||
|
||||
|
||||
usage = """upload-file [options]
|
||||
|
||||
Upload a file, and print the corresponding URI.
|
||||
|
|
|
@ -52,13 +52,16 @@ streams_to_watch = ['new members']
|
|||
# These streams will cause anyone who sends a message there to be removed from the watchlist
|
||||
streams_to_cancel = ['development help']
|
||||
|
||||
|
||||
def get_watchlist() -> List[Any]:
|
||||
storage = client.get_storage()
|
||||
return list(storage['storage'].values())
|
||||
|
||||
|
||||
def set_watchlist(watchlist: List[str]) -> None:
|
||||
client.update_storage({'storage': dict(enumerate(watchlist))})
|
||||
|
||||
|
||||
def handle_event(event: Dict[str, Any]) -> None:
|
||||
try:
|
||||
if event['type'] == 'realm_user' and event['op'] == 'add':
|
||||
|
@ -74,11 +77,13 @@ def handle_event(event: Dict[str, Any]) -> None:
|
|||
if event['message']['sender_email'] in watchlist:
|
||||
watchlist.remove(event['message']['sender_email'])
|
||||
if stream not in streams_to_cancel:
|
||||
client.send_message({
|
||||
'type': 'private',
|
||||
'to': event['message']['sender_email'],
|
||||
'content': welcome_text.format(event['message']['sender_short_name'])
|
||||
})
|
||||
client.send_message(
|
||||
{
|
||||
'type': 'private',
|
||||
'to': event['message']['sender_email'],
|
||||
'content': welcome_text.format(event['message']['sender_short_name']),
|
||||
}
|
||||
)
|
||||
set_watchlist(watchlist)
|
||||
return
|
||||
except Exception as err:
|
||||
|
@ -89,5 +94,6 @@ def start_event_handler() -> None:
|
|||
print("Starting event handler...")
|
||||
client.call_on_each_event(handle_event, event_types=['realm_user', 'message'])
|
||||
|
||||
|
||||
client = zulip.Client()
|
||||
start_event_handler()
|
||||
|
|
|
@ -12,12 +12,15 @@ logging.basicConfig()
|
|||
|
||||
log = logging.getLogger('zulip-send')
|
||||
|
||||
|
||||
def do_send_message(client: zulip.Client, message_data: Dict[str, Any]) -> bool:
|
||||
'''Sends a message and optionally prints status about the same.'''
|
||||
|
||||
if message_data['type'] == 'stream':
|
||||
log.info('Sending message to stream "%s", subject "%s"... ' %
|
||||
(message_data['to'], message_data['subject']))
|
||||
log.info(
|
||||
'Sending message to stream "%s", subject "%s"... '
|
||||
% (message_data['to'], message_data['subject'])
|
||||
)
|
||||
else:
|
||||
log.info('Sending message to %s... ' % (message_data['to'],))
|
||||
response = client.send_message(message_data)
|
||||
|
@ -28,6 +31,7 @@ def do_send_message(client: zulip.Client, message_data: Dict[str, Any]) -> bool:
|
|||
log.error(response['msg'])
|
||||
return False
|
||||
|
||||
|
||||
def main() -> int:
|
||||
usage = """zulip-send [options] [recipient...]
|
||||
|
||||
|
@ -41,22 +45,29 @@ def main() -> int:
|
|||
|
||||
parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
|
||||
|
||||
parser.add_argument('recipients',
|
||||
nargs='*',
|
||||
help='email addresses of the recipients of the message')
|
||||
parser.add_argument(
|
||||
'recipients', nargs='*', help='email addresses of the recipients of the message'
|
||||
)
|
||||
|
||||
parser.add_argument('-m', '--message',
|
||||
help='Specifies the message to send, prevents interactive prompting.')
|
||||
parser.add_argument(
|
||||
'-m', '--message', help='Specifies the message to send, prevents interactive prompting.'
|
||||
)
|
||||
|
||||
group = parser.add_argument_group('Stream parameters')
|
||||
group.add_argument('-s', '--stream',
|
||||
dest='stream',
|
||||
action='store',
|
||||
help='Allows the user to specify a stream for the message.')
|
||||
group.add_argument('-S', '--subject',
|
||||
dest='subject',
|
||||
action='store',
|
||||
help='Allows the user to specify a subject for the message.')
|
||||
group.add_argument(
|
||||
'-s',
|
||||
'--stream',
|
||||
dest='stream',
|
||||
action='store',
|
||||
help='Allows the user to specify a stream for the message.',
|
||||
)
|
||||
group.add_argument(
|
||||
'-S',
|
||||
'--subject',
|
||||
dest='subject',
|
||||
action='store',
|
||||
help='Allows the user to specify a subject for the message.',
|
||||
)
|
||||
|
||||
options = parser.parse_args()
|
||||
|
||||
|
@ -93,5 +104,6 @@ def main() -> int:
|
|||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue