-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_day.sh
executable file
·47 lines (37 loc) · 1.23 KB
/
generate_day.sh
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env sh
# Generate new module for the given day
# Usage: ./generate_module.sh <day>
# Example: ./generate_module.sh 1
# shellcheck source=/dev/null
. ./.env
# check if the day is given
if [ -z "$1" ]; then
echo "Usage: ./generate_module.sh <day>"
exit 1
fi
# check if the day is a number
if ! expr "$1" : '^[0-9]\+$' >/dev/null; then
echo "Day must be a number"
exit 1
fi
# check if the day is in the range
if [ "$1" -lt 1 ] || [ "$1" -gt 25 ]; then
echo "Day must be in the range 1-25"
exit 1
fi
# generate module only if the day is not already generated
if [ ! -d "src/days/day_$(printf "%02d" "$1")" ]; then
# create the directory in src/days/day_n with 2 digits
mkdir -p "src/days/day_$(printf "%02d" "$1")"
# create the part1.py and part2.py files containing template.py
for PART in $(seq 1 2); do
cp template.py "src/days/day_$(printf "%02d" "$1")/part${PART}.py"
done
# create the __init__.py file
touch "src/days/day_$(printf "%02d" "$1")/__init__.py"
fi
if [ ! -d "inputs" ]; then
mkdir "inputs"
fi
# use aoc cli to download just the input to inputs/day_{n:02d}.txt
aoc download --year "$YEAR" --day "$1" --input-only --input-file "inputs/day_$(printf "%02d" "$1").txt"