30 lines
971 B
Bash
Executable File
30 lines
971 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 from https://adventofcode.com/$year/day/$webitem/input"
|
|
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
|