Last active
April 20, 2017 08:10
-
-
Save AlexanderC/5d5b5bf359a1499d6e797e1a37599480 to your computer and use it in GitHub Desktop.
Dump Moldovan emojis from https://www.pinterest.com/fruitware/moldavian-emoji/ in a Slack compatible format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
_emoji_dir="$1" | |
_tmp_dir=$(mktemp -d) | |
_suffix=".emoji.png" | |
_script="_emoji.js" | |
_url="https://www.pinterest.com/fruitware/moldavian-emoji/" | |
_lib="pinterest-api" | |
die() | |
{ | |
echo "$1" 1>&2 | |
exit 1 | |
} | |
spinner() | |
{ | |
local pid=$! | |
local delay=0.025 | |
local spinstr='|/-\' | |
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do | |
local temp=${spinstr#?} | |
printf "\e[?25l%c" "$spinstr" 1>&2 | |
local spinstr=$temp${spinstr%"$temp"} | |
sleep $delay | |
printf "\e[?25l\r" 1>&2 | |
done | |
printf "\e[?25h" 1>&2 | |
} | |
emojify() | |
{ | |
local source="$1" | |
local dest="${source%.*}$_suffix" | |
convert -monitor -quality 100 -trim +repage -fuzz 30% -flatten "$source" "$dest" || die "Error trimming $source" | |
convert -monitor -quality 100 -fuzz 20% -transparent white "$dest" "$dest" || die "Error removing background from $dest" | |
convert -monitor -quality 100 -resize 128x128 "$dest" "$dest" || die "Error resizing $dest" | |
} | |
download() | |
{ | |
local emoji_url="$1" | |
local emoji_path="$2" | |
curl -XGET "$emoji_url" --fail --progress -o "$emoji_path" || die "Error fetching image from $emoji_url" | |
} | |
if [ ! -d "$_emoji_dir" ]; then | |
die "Missing output directory $_emoji_dir" | |
elif [ -z `which npm` ] || [ -z `which node` ] || [ -z `which curl` ] || [ -z `which convert` ] || [ -z `which base64` ]; then | |
die "You should have the following binaries available: npm, node, curl, convert, base64" | |
fi | |
echo "Ensure $_lib installed" | |
ls $(npm -g root)"/$_lib" &>/dev/null || npm install -g "$_lib" --silent || die "Error installing $_lib dependency" | |
echo "Dumping Moldovan emoji's from $_url" | |
echo "Y29uc3QgUElOX0FDQ09VTlQgPSAnZnJ1aXR3YXJlJzsKY29uc3QgUElOX0JPQVJEID0gJ21vbGRhdmlhbi1lbW9qaSc7Cgpjb25zdCBwYXRoID0gcmVxdWlyZSgncGF0aCcpOwpjb25zdCBwaW50ZXJlc3RBcGkgPSByZXF1aXJlKHBhdGgucmVzb2x2ZShwYXRoLmRpcm5hbWUocHJvY2Vzcy5hcmd2WzBdKSwgJy4uL2xpYi9ub2RlX21vZHVsZXMvcGludGVyZXN0LWFwaScpKTsKY29uc3QgcGludGVyZXN0ID0gcGludGVyZXN0QXBpKFBJTl9BQ0NPVU5UKTsKCnBpbnRlcmVzdC5nZXRQaW5zRnJvbUJvYXJkKFBJTl9CT0FSRCwgdHJ1ZSwgcGlucyA9PiB7CiAgcGlucy5kYXRhLm1hcChwaW4gPT4gewogICAgaWYgKE9iamVjdC5rZXlzKHBpbi5pbWFnZXMpLmxlbmd0aCA+IDApIHsKICAgICAgY29uc3QgZW1vamkgPSBwaW4uaW1hZ2VzW09iamVjdC5rZXlzKHBpbi5pbWFnZXMpWzBdXTsKICAgICAgCiAgICAgIHByb2Nlc3Muc3Rkb3V0LndyaXRlKGAke2Vtb2ppLnVybH1cbmApOwogICAgfQogIH0pOwp9KTsK" | base64 --decode > "$_tmp_dir/$_script" | |
for emoji_url in $(node "$_tmp_dir/$_script" & spinner || die "Error fetching emojis metadata from $_url") | |
do | |
emoji_name=${emoji_url##*/} | |
emoji_path="$_tmp_dir/$emoji_name" | |
download "$emoji_url" "$emoji_path" | |
emojify "$emoji_path" | |
cp "${emoji_path%.*}$_suffix" "$_emoji_dir/$emoji_name" || die "Error copying emoji to $_emoji_dir/$emoji_name" | |
done | |
rm -rf "$_tmp_dir" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment