物理の駅 Physics station by 現役研究者

テクノロジーは共有されてこそ栄える

(Solved v2.2.2 and later) Slackdump_v2.2.0 Katakana charactors directory problem

日本語訳は下に (Japanese translation below)

This problem was fixed in version v2.2.2 and later. Please download the latest version of the slackdump.

There is an excelent software called slackdump that allows you to back up all your visible Slack messages and attachments without special permissions, i.e. administrator or owner.

github.com

When the channel name contains Japanese full-width katakana characters, the directory name to save the slack message data (eg. 2022-10-10.json) will be half-width katakana with using slackdump. Attachments are saved in correct full-width katakana directories.

To temporarily solve this problem, I prepared a python script that copies the message data = JSON files in the half-width katakana directory to the full-width katakana directory.

import zipfile
import mojimoji # need install mojimoji to convert half-width katakana to full-width katakana
import json
import shutil
import os
zipPath_org = r"C:\Users\Masahiro\Downloads\escan.zip"
zipPath = os.path.join(os.path.dirname(zipPath_org),
                       os.path.splitext(os.path.basename(zipPath_org))[0]+"_new"+os.path.splitext(os.path.basename(zipPath_org))[1])

shutil.copy(zipPath_org,zipPath)
with zipfile.ZipFile(zipPath, 'a') as myzip:
    infolist = myzip.infolist()

    channels = json.load(myzip.open('channels.json'))
    channel_names = []
    for channel in channels:
        channel_names.append(channel['name'])
        # print(channel['name']) for debug
        
    for info in infolist:
        if info.filename.split('/')[0] not in channel_names:
            channel_half_width = info.filename.split('/')[0]
            channel_full_width = mojimoji.han_to_zen(channel_half_width, ascii=False, kana=True, digit=False)
            if channel_half_width == channel_full_width:continue
            if channel_full_width not in channel_names:
                print(channel_full_width)
            assert(channel_full_width in channel_names)
            filename_new = channel_full_width+info.filename[len(channel_half_width):]
            # print(info.filename,"->",filename_new) # for debug
            myzip.writestr(filename_new,myzip.open(info.filename).read())
    myzip.close()
print(zipPath, "is output.")

(Japanese translation)

バージョンv2.2.2以降で、この問題は修正済みです最新バージョンのslackdumpをダウンロードしてください。

Slack上で見えているメッセージを、管理者・オーナーなどの特別な権限がなくても、バックアップできる slackdumpという素晴らしいソフトウェアを見つけました。

github.com

チャンネル名に日本語の全角カタカナ文字を含む場合、slackdumpでメッセージデータ(例: 2022-10-10.json)の保存先のディレクトリ名が、半角カタカナになってしまうバグがあるようです。添付ファイルは、全角カタカナのディレクトリに正しく保存されています。

この問題を一時的に解決するため、半角カタカナのディレクトリにあるメッセージデータ = JSONファイルを全角カタカナ文字のディレクトリにコピーするPythonスクリプトを用意しました。

参照

kenkyu-note.hatenablog.com