Skip to content

Instantly share code, notes, and snippets.

@guypursey
Last active August 29, 2015 14:07
Show Gist options
  • Save guypursey/e46849e9fe158d841622 to your computer and use it in GitHub Desktop.
Save guypursey/e46849e9fe158d841622 to your computer and use it in GitHub Desktop.
Add or remove post on Scriptogram, pulling in relevant metadata from a separate file
# Usage: ./autoscrp.sh [OPTION]... [FILE]
# Publish FILE to Scriptogr.am account (grabbing metadata as we go).
# FILE should have no extension.
#
# Expects metascrp.txt accompanying named file to pull metadata from.
# Expects there two text files in location of script,
# one containing app key for Scriptogram,
# the other containing the user ID.
#
# -d Delete file.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ "$1" == "-d" ]
then
echo "Deleting..."
URL="http://scriptogr.am/api/article/delete/"
fileparam="-d filename=$2.md"
filedata=""
echo $2
else
echo "Adding..."
URL="http://scriptogr.am/api/article/post/"
fileparam="-d name=$1"
filedata=$(<metascrp.txt)$'\n\n'$(<$1.md)
echo $1
fi
curl \
--data-urlencode app_key@"$DIR/scrpakey.txt" \
--data-urlencode user_id@"$DIR/scrpuser.txt" \
"$fileparam" \
--data-urlencode text="$filedata" \
$URL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment