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.
This commit is contained in:
parent
a645ba233f
commit
7db4e36752
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue