-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch.sh
More file actions
executable file
·29 lines (26 loc) · 935 Bytes
/
fetch.sh
File metadata and controls
executable file
·29 lines (26 loc) · 935 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#/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