Created
June 9, 2017 20:44
-
-
Save haku/2cf842beb92ae1873a3c9a787c6f4b41 to your computer and use it in GitHub Desktop.
Calculate % progress reading a set of stories.
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/bash | |
set -eu | |
parts="$(grep '^-' './team-kimba.txt')" | |
awk_cmds=( | |
'{print $2 $3}' | |
"{split(\$0, a, \"/\"); b = a[2]; gsub(\"[ #',?]\", \"\", b); print b}" | |
"{b = \$0; gsub(\"^-|[ #',?()]\", \"\", b); gsub(\"/\", \"-\", b); print b}" | |
) | |
part_to_file() { | |
local part="$1" | |
for ac in "${awk_cmds[@]}" ; do | |
local n="$(echo "$part" | awk "$ac")" | |
local f="$(find './team_kimba' -maxdepth 1 -iname "$n.html")" | |
if [ -e "$f" ] ; then | |
echo "$f" | |
exit 0 | |
else | |
echo "n=$n" >&2 | |
fi | |
done | |
} | |
total_words=0 | |
read_words=0 | |
not_found=0 | |
while read part ; do | |
f="$(part_to_file "$part")" | |
if [ -e "$f" ] ; then | |
f_words="$(html-word-count -t "$f")" | |
(( total_words += $f_words )) | |
if [[ "$part" == *"#" ]] ; then | |
(( read_words += $f_words )) | |
fi | |
echo "$part => $f_words words." | |
else | |
echo "Not found: $part" | |
(( not_found += 1 )) | |
fi | |
done < <(echo "$parts") | |
(( percent = 100 * $read_words / $total_words )) | |
echo "Total words: $total_words" | |
echo "Read words: $read_words" | |
echo "Progress: $percent%" | |
echo "Not found: $not_found" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment