diff options
Diffstat (limited to 'games/mtg/cardToHtml.sh')
-rwxr-xr-x | games/mtg/cardToHtml.sh | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/games/mtg/cardToHtml.sh b/games/mtg/cardToHtml.sh new file mode 100755 index 0000000..c7a93dc --- /dev/null +++ b/games/mtg/cardToHtml.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +# cardToHtml.sh: Generates an image HTML tag of an MTG card, with the name of +# the card as alternate text and the image being a link to its Scryfall page. +# +# Usage: cardToHtml.sh CARDNAME +# +# Exotic dependencies: jq + +usageMessage="Usage: ${0} CARDNAME" + +error() { + printf '%s error: %s\n' "$0" "$*" >&2 +} + +errorAndUsage() { + printf '%s error: %s\n%s\n' "$0" "$*" "$usageMessage" >&2 +} + +# Process options +while getopts ':' opt; do + case $opt in + + '?' ) + printf '%s\n' "$usageMessage" >&2 + exit 1 + + esac +done +shift $((OPTIND - 1)) + +json="$(getScryfallJSON.sh "$@")" +[ -z "$json" ] && exit 1 +cardName="$(echo "$json" | jq -r '.name')" +imageUrl="$(echo "$json" | jq -r '.image_uris.large' | sed 's/?.*$//')" +scryfallUrl="$(echo "$json" | jq -r '.scryfall_uri' | sed 's/?.*$//')" + +printf '<a href="%s"> + <img src="%s" + alt="%s"> +</a>\n' "$scryfallUrl" "$imageUrl" "$cardName" |