Last active
October 25, 2018 17:54
-
-
Save JamesHagerman/7c9a9fdb34e7d4e961c1e74fba650443 to your computer and use it in GitHub Desktop.
Alien guy is totally underused. This script changes that. It also supports others, but that's boring...
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
| #!/bin/bash | |
| # Yeah, it's a hack. Deal with it. | |
| # template ids are here: https://api.imgflip.com/get_memes | |
| # Usage: | |
| # memes.sh <bottom text> | |
| # memes.sh -t <top text> -m <template id> <bottom text> | |
| TEMPLATE_ID=101470 | |
| TOP_TEXT= | |
| BOTTOM_TEXT= | |
| while test $# != 0 | |
| do | |
| case "$1" in | |
| -t) shift; TOP_TEXT=$1 ;; | |
| -m) shift; TEMPLATE_ID=$1 ;; | |
| *) BOTTOM_TEXT=$1 ;; | |
| esac | |
| shift | |
| done | |
| echo "Building meme..." | |
| if [ 101470 != "$TEMPLATE_ID" ]; then echo " using id: $TEMPLATE_ID"; fi | |
| if [ -n "$TOP_TEXT" ]; then | |
| echo " with top text: $TOP_TEXT " | |
| TT_ENCODED=`node -e 'console.log(encodeURIComponent(process.argv[1]))' "$TOP_TEXT"` | |
| TT_URL="&text0=$TT_ENCODED" | |
| fi | |
| if [ -n "$BOTTOM_TEXT" ]; then | |
| echo " with bottom text: $BOTTOM_TEXT " | |
| BT_ENCODED=`node -e 'console.log(encodeURIComponent(process.argv[1]))' "$BOTTOM_TEXT"` | |
| BT_URL="&text1=$BT_ENCODED" | |
| fi | |
| TEMPLATE_URL="template_id=$TEMPLATE_ID" # Has to be first | |
| BODY_URL="$TEMPLATE_URL&username=imgflip_hubot&password=imgflip_hubot$TT_URL$BT_URL" | |
| JSON=`wget --quiet \ | |
| --method POST \ | |
| --header 'content-type: application/x-www-form-urlencoded' \ | |
| --header 'cache-control: no-cache' \ | |
| --body-data $BODY_URL \ | |
| --output-document \ | |
| - http://api.imgflip.com/caption_image` | |
| #echo "oops:$JSON" | |
| URL=`node -e "console.log(JSON.parse(process.argv[1]).data.url)" $JSON` | |
| echo "Trying to open pening $URL..." | |
| if [ ! -x "$(command -v xdg-open)" ]; then | |
| xdg-open $URL &> /dev/null | |
| else | |
| open -n $URL | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment