Day 01
This commit is contained in:
32
newday.sh
Executable file
32
newday.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
# load .env
|
||||
if [ -f .env ]; then
|
||||
set -o allexport; source .env; set +o allexport
|
||||
fi
|
||||
|
||||
# Create dir / abort if exists
|
||||
f="day$(printf %02d $1)"
|
||||
echo "$f"
|
||||
mkdir "$f"
|
||||
if [ $? -ne 0 ]; then { echo "$f already exists" ; exit 1; } fi
|
||||
|
||||
# create part files with template
|
||||
txt=$(cat <<EOF
|
||||
#!/usr/bin/env python3
|
||||
|
||||
lines = (x.strip() for x in open("input.txt"))
|
||||
|
||||
for line in lines:
|
||||
pass
|
||||
EOF
|
||||
)
|
||||
echo "$txt" > "$f/part1.py"
|
||||
echo "$txt" > "$f/part2.py"
|
||||
|
||||
# fetch input (set AOC_SESSION in .env file or as env var)
|
||||
curl --request GET -sL \
|
||||
--cookie "session=$AOC_SESSION" \
|
||||
--url "https://adventofcode.com/2022/day/$(echo $1 | sed 's/^0*//')/input"\
|
||||
--output "$f/input.txt"
|
||||
|
||||
# git
|
||||
git add "$f/*"
|
||||
Reference in New Issue
Block a user