From 7db4e36752165c0a02543772dd106b9796c422ba Mon Sep 17 00:00:00 2001 From: rht Date: Thu, 5 Oct 2017 14:08:43 +0200 Subject: [PATCH] slack: Add minor changes. Set default value to be False for message's has_image Update type signature to functions. Set default to be false for msg's has_link. --- .../integrations/slack/slackdata2zulipdata.py | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/zulip/integrations/slack/slackdata2zulipdata.py b/zulip/integrations/slack/slackdata2zulipdata.py index 3f81fb0..aef0d84 100755 --- a/zulip/integrations/slack/slackdata2zulipdata.py +++ b/zulip/integrations/slack/slackdata2zulipdata.py @@ -6,17 +6,26 @@ import sys import argparse import shutil import subprocess -import zipfile + +from typing import Any, Dict, List +# stubs +user_profile_stub = Dict[str, Any] +added_users_stub = Dict[str, int] # Transported from https://github.com/zulip/zulip/blob/master/zerver/lib/export.py -def rm_tree(path): - # type: (str) -> None +def rm_tree(path: str) -> None: if os.path.exists(path): shutil.rmtree(path) -def users2zerver_userprofile(slack_dir, realm_id, timestamp, domain_name): - # type: () -> None +def users2zerver_userprofile(slack_dir: str, realm_id: int, timestamp: Any, + domain_name: str) -> (List[user_profile_stub], added_users_stub): + """ + Returns: + 1. zerver_userprofile, which is a list of user profile + 2. added_users, which is a dictionary to map from slack user id to zulip + user id + """ print('######### IMPORTING USERS STARTED #########\n') users = json.load(open(slack_dir + '/users.json')) zerver_userprofile = [] @@ -215,7 +224,7 @@ def channelmessage2zerver_message(slack_dir, channel, added_users, added_channel zulip_message = dict( sending_client=1, rendered_content_version=1, # This is Zulip-specific - has_image=msg['has_image'], + has_image=msg.get('has_image', False), subject=channel, # This is Zulip-specific pub_date=msg['ts'], id=msg_id_count, @@ -226,13 +235,11 @@ def channelmessage2zerver_message(slack_dir, channel, added_users, added_channel rendered_content=text, # slack doesn't cache this recipient=added_channels[channel], last_edit_time=None, - has_link=msg['has_link']) + has_link=msg.get('has_link', False)) zerver_message.append(zulip_message) return zerver_message -def main(slack_zip_file): - # type: (str) -> None - +def main(slack_zip_file: str) -> None: slack_dir = slack_zip_file.replace('.zip', '') subprocess.check_call(['unzip', slack_zip_file]) # with zipfile.ZipFile(slack_zip_file, 'r') as zip_ref: