Confluence Emoji to XWiki

Last modified by Nikita Petrenko on 2025/02/12 12:24

cogReplaces all Confluence emojis within exports with UTF-8 equivalents so that the xwiki migrator can migrate the emojis.
TypeSnippet
CategoryOther
Developed by

Wolpertinger Wolpertinger

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Table of contents

Description

The xwiki migrator cannot read confluence's own emojis during migration. This Pythonscript replaces all these Confluence emojis with UTF-8 equivalents in the xml.zip exports. The xwiki migrator can then migrate the content with emojis.

use terminal: python emoji_replace.py myconfluenceexport.xml.zip

Pythonscript emoji_replace.py:

import argparse
import io
import zipfile

parser = argparse.ArgumentParser()
parser.add_argument('file')
args = parser.parse_args()

con2uni = { # mapping confluence emoji-names to unicode Emojis
    "smile": "\N{slightly smiling face}",
    "sad": "\N{disappointed face}",
    "cheeky": "\U0001F61B",
    "laugh": "\U0001F603",
    "wink": "\N{winking face}",
    "thumbs-up": "\N{thumbs up sign}",
    "thumbs-down": "\N{thumbs down sign}",
    "information": "\N{information source}",
    "tick": "\N{white heavy check mark}",
    "cross": "\N{cross mark}",
    "warning": "\N{warning sign}",
    "plus": "\N{heavy plus sign}",
    "minus": "\N{heavy minus sign}",
    "question": "\N{black question mark ornament}",
    "light-on": "\N{electric light bulb}",
    "light-off": "\N{medium white circle}",
    "yellow-star": "\N{large yellow circle}",
    "green-star": "\N{large green circle}",
    "red-star": "\N{large red circle}",
    "blue-star": "\N{large blue circle}", 
}

def convert_to_unicode(f):
    out = ""
    data = f.read()
    for confluence_name, unicode_name in con2uni.items():
        print(unicode_name, end="", flush=True)
        data = data.replace(f'<ac:emoticon ac:name="{confluence_name}" />', unicode_name)
    print()
    return data

zin = zipfile.ZipFile (args.file, 'r')
zout = zipfile.ZipFile (f'{args.file}_fixed_emoticons.zip', 'w')
for item in zin.infolist():
    if (item.filename != 'entities.xml'):
        print(f"copy {item.filename}")
        buffer = zin.read(item.filename)
    else:
        print(f"replace emoticons in {item.filename}")
        with io.TextIOWrapper(zin.open("entities.xml"), encoding="utf-8") as f:
            buffer = convert_to_unicode(f)
    zout.writestr(item, buffer)

zout.close()
zin.close()

Get Connected