#!/bin/sh
rm -rf /tmp/apgte
mkdir /tmp/apgte
curl -s 'https://practicalguidetoevil.wordpress.com/table-of-contents/' | hq 'sel [class=entry-content]' | grep -v sharedaddy | grep -v jp-relatedposts | while read line; do
printf '%s' "$line" | grep -q "$" && {
printf 'book\t%s\n' "$line" | sed 's/<[^<>]*>//g'
} || {
printf '%s' "$line" | hq 'sel a | totext' | sed -e 's/ ( /\t/' -e 's/..$//'
}
done | while read -r line; do
echo $line
test "$(printf '%s' "$line" | cut -f 1)" = "book" && {
echo $book.pdf
test -n "$book" && weasyprint /tmp/"$book.html" /tmp/apgte/"$book.pdf"
echo Commentated $book.pdf
test -n "$book" && weasyprint /tmp/"Commentated $book.html" /tmp/apgte/"Commentated $book.pdf"
book="$(printf '%s' "$line" | cut -f 2)"
printf "
%s
" "$book" >/tmp/"$book.html"
printf "%s
" "$book" >/tmp/"Commentated $book.html"
} || {
curl -s "$(printf '%s' "$line" | cut -f 2)" >/tmp/apgte.html
{
printf ''
printf '%s' "$line" | cut -f 1
printf '
'
hq 'sel [class=entry-content]' > /tmp/"$book.html"
{
printf ''
printf '%s' "$line" | cut -f 1
printf '
'
hq 'sel [class=entry-content]'
'
hq 'sel .comment-content p:not(:last-child), .comment-author cite' /tmp/comments.html
hq 'sel li.comment | . class' ' "$((line - 1))"
awk 'BEGIN { a = 0 } /^ 1) { print >>"/tmp/comments2.html" } else { print } }' '
done
printf '
'
} >> /tmp/"Commentated $book.html"
}
done
echo $book.pdf
test -n "$book" && weasyprint /tmp/"$book.html" /tmp/apgte/"$book.pdf"
echo Commentated $book.pdf
test -n "$book" && weasyprint /tmp/"Commentated $book.html" /tmp/apgte/"Commentated $book.pdf"
printf "Extra Chapters
" >/tmp/"Extra Chapters.html"
printf "Extra Chapters
" >/tmp/"Commentated Extra Chapters.html"
curl -s 'https://practicalguidetoevil.wordpress.com/extra-chapters/' | hq 'sel [class=entry-content]' | grep -v sharedaddy | grep -v jp-relatedposts | while read line; do
printf '%s' "$line" | hq 'sel a | totext' | sed -e 's/ ( /\t/' -e 's/..$//'
done | while read -r line; do
echo $line
curl -s "$(printf '%s' "$line" | cut -f 2)" >/tmp/apgte.html
{
printf ''
printf '%s' "$line" | cut -f 1
printf '
'
hq 'sel [class=entry-content]' > /tmp/"Extra Chapters.html"
{
printf ''
printf '%s' "$line" | cut -f 1
printf '
'
hq 'sel [class=entry-content]'
'
hq 'sel .comment-content p:not(:last-child), .comment-author cite' /tmp/comments.html
hq 'sel li.comment | . class' ' "$((line - 1))"
awk 'BEGIN { a = 0 } /^ 1) { print >>"/tmp/comments2.html" } else { print } }' '
done
printf '
'
} >> /tmp/"Commentated Extra Chapters.html"
done
echo Extra Chapters
weasyprint "/tmp/Extra Chapters.html" "/tmp/apgte/Extra Chapters.pdf"
echo Commentated Extra Chapters
weasyprint "/tmp/Commentated Extra Chapters.html" "/tmp/apgte/Commentated Extra Chapters.pdf"