Files
AdventOfCode/fetch.sh
T
2025-11-30 16:53:44 +01:00

30 lines
935 B
Bash
Executable File

#/bin/sh
if [ ! -e cookies.txt ]; then
echo "No cookies.txt file exists"
exit 1
fi
list=$(find -name "Day*.cpp" | awk -F '/' '{print $3 "/" $4}' | awk -F '.' '{print $1}' | sed 's/Day//g' | sort)
for item in $list; do
year=$(echo $item | awk -F '/' '{print $1}')
day=$(echo $item | awk -F '/' '{print $2}')
dir="res/$year/day$day/input.txt"
if [ ! -e $dir ]; then
webitem=$(echo $day | sed 's/^0//g')
echo "Fetching $dir"
tmp_file=$(mktemp)
HTTP_CODE=$(curl -s -w "%{http_code}" -o "$tmp_file" --cookie cookies.txt https://adventofcode.com/$year/day/$webitem/input)
if [ "$HTTP_CODE" -eq 200 ]; then
mkdir -p "res/$year/day$day/"
touch "res/$year/day$day/test_input.txt"
mv "$tmp_file" $dir
else
echo "Failed to fetch with status: $HTTP_CODE"
rm "$tmp_file"
exit 1
fi
fi
done