Skip to content
This repository has been archived by the owner on Nov 7, 2019. It is now read-only.

WIP - script for gists #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions href_gister.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/zsh
# short script to gist-ize the output of href_extracter.
# relies on the presence of the ruby gem "gist" https://github.com/defunkt/gist

# set constants
# file containing URLS
OUTPUT="urls.txt"
# json file
JSON="collection.json"

# process options
# we need to provide "name", "url" and "description", as well as selector
# so we'll use -n, -u, -d,-s, respectively

while getopts ":u:s:n:d:h" opt; do
case $opt in
h)
echo "USAGE: href_gister -u URL [-s SELECTOR ] -d NAME -d \"DESCRIPTION\"
-u, -n and -d are mandatory. -s defaults to 'a'"
;;
u)
url=$OPTARG
;;
s)
selector=$OPTARG
;;
n)
name=$OPTARG
;;
d)
description=$OPTARG
;;

\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done

echo "-u $url -o $OUTPUT -s $selector -n $name -d $description"


if [[ ! ($url || $name ) ]]; then
echo "-u URL, -n NAME and -d DESCRIPTION are all required."
exit 1
fi

if [[ ! selector ]]; then
selector=a
fi

if [[ ! description ]]; then
description=""
fi

# extract the urls
echo "extract_href -u $url -o $OUTPUT -s $selector "
extract_href -u $url -o $OUTPUT -s $selector

# write the config file
echo '{ "name" : "'$name'",
"url" : "'$url'",
"description" : "'$description'"
}' > $JSON


# call gist
mygist=$(gist collection.json urls.txt -d "extract_href output from $url, \"$name\"")
echo "$mygist,$url" >> gists.txt
echo $mygist