cutthecord/emojireplace.py

46 lines
1.5 KiB
Python
Raw Normal View History

#!/bin/env python3
import os
import shutil
# REPLACE THESE LINES
extracted_discord_path = "/tmp/cutthecord/discord"
extracted_mutstd_path = "/var/www/mutant/72x72"
def clean_emoji_name(name):
name = name.lower().replace("_", "-")\
.replace("emoji_", "").replace("-fe0f", "")
return name
discord_emoji_path = os.path.join(extracted_discord_path, "res", "raw")
# Get file listings in relevant folders
discord_emojis = os.listdir(discord_emoji_path)
mutstd_emojis = os.listdir(extracted_mutstd_path)
# Clean names of mutantstd emojis so thar we can compare them
# to clean discord emojis later
clean_mutstd_emojis = {clean_emoji_name(emoji): emoji for
emoji in mutstd_emojis}
replace_counter = 0
# Go through each discord emoji, and clean their names
for emoji in discord_emojis:
clean_discord_emoji = clean_emoji_name(emoji)
# Check if said clean name of emoji is in clean mutstd list
if clean_discord_emoji in clean_mutstd_emojis:
# Get full unclean filename of mutantstd emoji, generate relevant paths
full_mutstd_name = clean_mutstd_emojis[clean_discord_emoji]
full_mutstd_path = os.path.join(extracted_mutstd_path, full_mutstd_name)
full_discord_path = os.path.join(extracted_discord_path, emoji)
# Copy and overwrite the discord emojis with the mutantstd alternatives
shutil.copyfile(full_mutstd_path, full_discord_path)
print("Replaced {} emoji.".format(full_mutstd_name))
replace_counter += 1
print("Done, {} emojis replaced.".format(replace_counter))