Created
March 5, 2014 06:23
-
-
Save debanjum/9362179 to your computer and use it in GitHub Desktop.
Extracts Quotes from GoodReads. Stores text file in Variety compatible format
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/sh | |
# Initialising Variables [Enter You Use Name in place of USER] | |
quotesdir='/home/USER/.config/variety/pluginconfig/quotes/quotes.txt' | |
# New Quotes: Clean Earlier Quotes | |
[[ $# -eq 1 && $1 == 'New' ]] && ( `mv -f "$quotesdir" /tmp/quotes_old.txt` ) | |
# Restore Earlier Quotes | |
[[ $# -eq 1 && $1 == 'Restore' ]] && ( `mv -f /tmp/quotes_old.txt "$quotesdir"` ) | |
# Quote Help | |
[[ $# -eq 1 && $1 == 'Help' ]] && ( | |
echo -e "Invalid Argument(s)\nCommand Format: $0 <Keyword1> <Keyword2>...\nExample: $0 Bill Watterson\nOR\nCommand Format: $0 [New/Restore/Help]\nExample: $0 New\n" ) | |
# Computing Ducky URL for Given Author Name | |
[ $# -eq 0 ] && ( wget -qL "http://duckduckgo.com/?q=\!+Bill+Watterson+quotes+goodreads" -O resolve.txt ) || ( | |
[ $# -eq 1 ] && ( wget -qL "http://duckduckgo.com/?q=\!+$1+quotes+goodreads" -O resolve.txt ) || ( | |
[ $# -eq 2 ] && ( wget -qL "http://duckduckgo.com/?q=\!+$1+$2+quotes+goodreads" -O resolve.txt ) || ( | |
[ $# -eq 3 ] && ( wget -qL "http://duckduckgo.com/?q=\!+$1+$2+$3+quotes+goodreads" -O resolve.txt ) || ( | |
[ $# -eq 4 ] && ( wget -qL "http://duckduckgo.com/?q=\!+$1+$2+$3+$4+quotes+goodreads" -O resolve.txt ) || ( | |
[ $# -eq 5 ] && ( wget -qL "http://duckduckgo.com/?q=\!+$1+$2+$3+$4+$5+quotes+goodreads" -O resolve.txt ) ) ) ) ) ) | |
wget $(sed -n "s/^.*uddg\=\(.*\)'><\/head.*$/\1/p" resolve.txt) -o output.txt # Make Ducky URL suitable for following. | |
wget -q $(sed -n "s/^.*(\(.*\)).*$/\1/p" output.txt) -O result.txt # Follow Ducky URL and Get Result | |
sed -n "s/^.*\(“.*”\).*$/\1/p" result.txt > quotes.txt # Extract Quotation Text | |
# Add Author Name | |
[ $# -eq 0 ] && ( sed -i "s/”/\" --Bill Watterson\n./g" quotes.txt ) || ( | |
[ $# -eq 1 ] && ( sed -i "s/”/\" --$1\n./g" quotes.txt ) || ( | |
[ $# -eq 2 ] && ( sed -i "s/”/\" --$1 $2\n./g" quotes.txt ) || ( | |
[ $# -eq 3 ] && ( sed -i "s/”/\" --$1 $2 $3\n./g" quotes.txt ) || ( | |
[ $# -eq 4 ] && ( sed -i "s/”/\" --$1 $2 $3 $4\n./g" quotes.txt ) || ( | |
[ $# -eq 5 ] && ( sed -i "s/”/\" --$1 $2 $3 $4 $5\n./g" quotes.txt ) ) ) ) ) ) | |
# Make Suitable For Use With Variety | |
sed -i 's/“/"/g' quotes.txt | |
sed -i 's/<br>/\n/g' quotes.txt | |
# Appending Text | |
`cat quotes.txt >> "$quotesdir"` | |
# Cleaning Directory | |
rm -f resolve.txt results.txt output.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment