python: Normalize quotes with Black.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-02-11 23:20:45 -08:00
committed by Tim Abbott
parent 11741543da
commit 6e4c3e41dc
989 changed files with 32792 additions and 32792 deletions

View File

@@ -34,59 +34,59 @@ Example: zulip-export --user=wdaher@zulip.com --api-key=a0b1c2d3e4f5a6b7c8d9e0f1
You can omit --user and --api-key arguments if you have a properly set up ~/.zuliprc
This script requires the Zulip API bindings to be installed."""
sys.path.append(os.path.join(os.path.dirname(__file__), '../../api'))
sys.path.append(os.path.join(os.path.dirname(__file__), "../../api"))
import zulip
parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
parser.add_argument('--stream', required=True)
parser.add_argument("--stream", required=True)
options = parser.parse_args()
client = zulip.init_from_options(options)
client.add_subscriptions([{"name": options.stream}])
queue = client.register(event_types=['message'])
max_id = queue['max_message_id']
queue = client.register(event_types=["message"])
max_id = queue["max_message_id"]
messages = []
request = {
'anchor': 0,
'num_before': 0,
'num_after': max_id,
'narrow': [{'operator': 'stream', 'operand': options.stream}],
'apply_markdown': False,
"anchor": 0,
"num_before": 0,
"num_after": max_id,
"narrow": [{"operator": "stream", "operand": options.stream}],
"apply_markdown": False,
}
print("Fetching messages...")
result = client.call_endpoint(
url='messages',
method='GET',
url="messages",
method="GET",
request=request,
)
if result['result'] != 'success':
if result["result"] != "success":
print("Unfortunately, there was an error fetching some old messages.")
print(result)
sys.exit(1)
for msg in result['messages']:
if msg['type'] != 'stream':
for msg in result["messages"]:
if msg["type"] != "stream":
continue
# Remove extraneous metadata
for k in [
'flags',
'edit_history',
'topic_links',
'avatar_url',
'recipient_id',
'content_type',
'client',
'sender_realm_str',
'id',
'type',
"flags",
"edit_history",
"topic_links",
"avatar_url",
"recipient_id",
"content_type",
"client",
"sender_realm_str",
"id",
"type",
]:
msg.pop(k, None)
messages.append(msg)
filename = f"zulip-{options.stream}.json"
with open(filename, 'w') as f:
with open(filename, "w") as f:
json.dump(messages, f, indent=0, sort_keys=False)
print(f"{len(messages)} messages exported to {filename}")
sys.exit(0)