Annotate API scripts.
This commit is contained in:
parent
28b697ac9d
commit
43bf07bf15
|
@ -27,12 +27,18 @@ import os
|
|||
import optparse
|
||||
import logging
|
||||
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
import zulip
|
||||
|
||||
logging.basicConfig()
|
||||
|
||||
log = logging.getLogger('zulip-send')
|
||||
|
||||
def do_send_message(client, message_data ):
|
||||
# type: (zulip.Client, Dict[str, Any]) -> bool
|
||||
'''Sends a message and optionally prints status about the same.'''
|
||||
|
||||
if message_data['type'] == 'stream':
|
||||
|
@ -49,6 +55,7 @@ def do_send_message(client, message_data ):
|
|||
return False
|
||||
|
||||
def main(argv=None):
|
||||
# type: (Optional[List[str]]) -> int
|
||||
if argv is None:
|
||||
argv = sys.argv
|
||||
|
||||
|
@ -63,10 +70,6 @@ def main(argv=None):
|
|||
'--user' and '--api-key' arguments.
|
||||
"""
|
||||
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
import zulip
|
||||
|
||||
parser = optparse.OptionParser(usage=usage)
|
||||
|
||||
# Grab parser options from the API common set
|
||||
|
|
|
@ -26,6 +26,8 @@ import sys
|
|||
import os
|
||||
import optparse
|
||||
|
||||
from typing import Any, Dict
|
||||
|
||||
usage = """print-events --user=<bot's email address> --api-key=<bot's api key> [options]
|
||||
|
||||
Prints out certain events received by the indicated bot or user matching the filter below.
|
||||
|
@ -44,6 +46,7 @@ parser.add_option_group(zulip.generate_option_group(parser))
|
|||
client = zulip.init_from_options(options)
|
||||
|
||||
def print_event(event):
|
||||
# type: (Dict[str, Any]) -> None
|
||||
print(event)
|
||||
|
||||
# This is a blocking call, and will continuously poll for new events
|
||||
|
|
|
@ -26,6 +26,8 @@ import sys
|
|||
import os
|
||||
import optparse
|
||||
|
||||
from typing import Any, Dict
|
||||
|
||||
usage = """print-messages --user=<bot's email address> --api-key=<bot's api key> [options]
|
||||
|
||||
Prints out each message received by the indicated bot or user.
|
||||
|
@ -44,6 +46,7 @@ parser.add_option_group(zulip.generate_option_group(parser))
|
|||
client = zulip.init_from_options(options)
|
||||
|
||||
def print_message(message):
|
||||
# type: (Dict[str, Any]) -> None
|
||||
print(message)
|
||||
|
||||
# This is a blocking call, and will continuously poll for new messages
|
||||
|
|
Loading…
Reference in a new issue