some dumb grep problems
parent
b4335f764a
commit
d682f836b4
25
poc.sh
25
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'
|
||||
|
|
|
|||
Loading…
Reference in New Issue