#!/usr/bin/env bash
# download/get files.html
# find (Events|Players|Openings updated): Month YYYY
# => store in last update
# => if one changed -> process
# in files.html
# div "Players"
# => table below
# => folder "players/"
# div "Openings"
# h2 "Modern Queen Pawn", "Classical Queen Pawn", "Modern King Pawn", "Classical King Pawn", "Flank and Unorthodox"
# => table below each h2
# => folder "openings/"
# div "Events"
# h2 "Tournaments", "Candidates and Interzonals", "World Championships"
# has to be YYYYMMDD
current_date="${1}";
current_date='20230718';
files=("Candidates_and_Interzonals" "Classical_King_Pawn" "Classical_Queen_Pawn" "Flank_and_Unorthodox" "Modern_King_Pawn" "Modern_Queen_Pawn" "Players" "Tournaments" "World_Championships");
folder="pgnmentor-files/"
if [ ! -d "${folder}" ]; then
echo "Missing $folder";
exit;
fi;
for i in "${files[@]}"; do
file=${i//_/ }".${current_date}.txt";
output=${i//_/ }".pgn";
if [ -f "${file}" ]; then
echo "OK: $file";
rm -f "${output}";
while read -r pgn; do
if [ -f "${folder}${pgn}" ]; then
cat "${folder}${pgn}" >> "${output}";
echo -n "."
else
echo "[!!] Missing ${folder}${pgn}";
fi;
done <"${file}";
echo "[DONE]";
fi;
done;
# __END__