From d682f836b407e3b10966ede80b28a09016105a6e Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Wed, 15 Dec 2021 08:07:59 -0700 Subject: [PATCH] some dumb grep problems --- poc.sh | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/poc.sh b/poc.sh index fd8d0be..f9e4b51 100644 --- a/poc.sh +++ b/poc.sh @@ -4,11 +4,15 @@ main() { set -e set -o pipefail - #set -x + local output="${1:-$(mktemp -d)}" log "$output" + #set -x + + #scrape_book_chapter https://www.dndbeyond.com/compendium/rules/dmg/appendix-b-monster-lists + #scrape_book_chapter https://www.dndbeyond.com/compendium/rules/phb/credits | less #list_chapters_in_book https://www.dndbeyond.com/sources/sdw @@ -47,7 +51,7 @@ scrape_book() { local output="$1" local book_url="$2" - if [ -d "$output" ] && ls "$output"/* && [ ! -f "$output/.wip" ]; then + if [ -d "$output" ] && ls "$output"/* &> /dev/null && [ ! -f "$output/.wip" ]; then log "$book_url already in $output" return fi @@ -129,11 +133,18 @@ html_to_markdown() { | sed "s/\\\\\([\"']\)/\1/g" )" local target="$( - (echo "$out" | grep -q '^##* Appendix' && echo Appendix) \ - || (echo "$out" | grep -q '^##* Chapter' && echo Chapter) \ - || (echo "$out" | grep -q '^##* Introduction' && echo Introduction) \ - || (echo "$out" | grep -q '^##* Credits' && echo Credits) \ - || echo Chapter + if echo "$out" | grep '^##* Appendix' &> /dev/null; then + echo Appendix + elif echo "$out" | grep '^##* Chapter' &> /dev/null; then + echo Chapter + elif echo "$out" | grep '^##* Introduction' &> /dev/null; then + echo Introduction + elif echo "$out" | grep '^##* Credits' &> /dev/null; then + echo Credits + else + log WARNING: NOTHING INDICITIVE OF TYPE OF CONTENT FOUND + echo Chapter + fi )" echo "$out" \ | sed -e '/^# '"$target"'/p' -e '0,/^# '"$target"'/d'