Files
AdventOfCode/fetch.sh
T
Thraix a9ac1c2c98 Add generate_days script
- Add generate_days script to generate templated files for an advent of
  code year.
- Optimize the fetch.sh script (remove awk usage)
2026-07-25 19:57:11 +02:00

30 lines
916 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=${item%/*} # remove everything before /
day=${item#*/} # remove everything after /
dir="res/$year/day$day/input.txt"
if [ ! -e $dir ]; then
webitem=${day#0}
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