Skip to content

Instantly share code, notes, and snippets.

@KisaragiEffective
Created September 9, 2023 13:10
Show Gist options
  • Save KisaragiEffective/293a63db36abadf44a53dd975d148a79 to your computer and use it in GitHub Desktop.
Save KisaragiEffective/293a63db36abadf44a53dd975d148a79 to your computer and use it in GitHub Desktop.
Grub all emoji from a misskey server and outputs its width and height.
#!/bin/bash
# SPDX-FileCopyrightText: 2023 Kisaragi Marine <kisaragi.marine@gmail.com>
# SPDX-License-Identifier: MIT OR Apache-2.0
set +x
die() {
echo "$@" >&2
exit 1
}
if ! command -v curl &> /dev/null; then
die "This script requires curl."
fi
if ! command -v jq &> /dev/null; then
die "This script requires curl."
fi
if ! command -v convert &> /dev/null; then
die "This script requires ImageMagick."
fi
readonly UA='User-Agent: KisaragiEffective/list-aspect-ratio/0.1'
readonly MISSKEY_HOST='https://dummy.local'
readonly emojis="$(curl -sSL -H "$UA" "$MISSKEY_HOST/api/emojis" | jq -r '.emojis | map([.name, .url]) | .[] | @csv')"
for emoji in $emojis; do
readonly emoji_url="$(echo "$emoji" | awk -F, '{ print $2 }' | sed -E 's/^"(.*)"$/\1/')"
readonly emoji_name="$(echo "$emoji" | awk -F, '{ print $1 }' | sed -E 's/^"(.*)"$/\1/')"
# echo "processing $emoji_url"
readonly image_path="$(mktemp)"
curl -sSL -H "$UA" "$emoji_url" > "$image_path"
readonly tmp_err="$(mktemp)"
(convert "$image_path" -print '{"result": "ok", "width": %w, "height": %h}' /dev/null 2>"$tmp_err" || jq '{"result": "error", "reason": .}' < "$tmp_err") | \
jq --arg name "$emoji_name" '. + {"name": $name}'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment