2023-12-06 14:59:56 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
today() {
|
|
|
|
TODAYDIR="$AOCROOT/$CURRYEAR/day$CURRDAY"
|
|
|
|
if [ ! -d $TODAYDIR ]; then
|
|
|
|
mkdir $TODAYDIR
|
|
|
|
fi
|
2023-12-07 16:41:03 +00:00
|
|
|
echo $TODAYDIR
|
2023-12-06 14:59:56 +00:00
|
|
|
}
|
|
|
|
|
2023-12-06 15:13:56 +00:00
|
|
|
getsharelink() {
|
|
|
|
echo "Getting share path"
|
|
|
|
YR=$CURRYEAR
|
|
|
|
DY=$CURRDAY
|
|
|
|
|
|
|
|
PWD=$(pwd)
|
|
|
|
PWD=${PWD#$AOCROOT/}
|
|
|
|
if [[ "$PWD" =~ ^[1-9][0-9]{3}/day[0-2][0-9]$ ]]; then
|
|
|
|
YR=${PWD:0:4}
|
|
|
|
DY=${PWD:5:5}
|
|
|
|
DY=${DY/day/}
|
|
|
|
fi
|
|
|
|
echo "https://git.bullercodeworks.com/brian/adventofcode/src/branch/main/$YR/day$DY/main.go"
|
|
|
|
}
|
|
|
|
|
2023-12-06 14:59:56 +00:00
|
|
|
getproblem() {
|
|
|
|
YR=$CURRYEAR
|
|
|
|
DY=$CURRDAY
|
2023-12-07 16:41:03 +00:00
|
|
|
DIRDY=$CURRDAY
|
2023-12-06 14:59:56 +00:00
|
|
|
|
|
|
|
PWD=$(pwd)
|
|
|
|
PWD=${PWD#$AOCROOT/}
|
|
|
|
if [[ "$PWD" =~ ^[1-9][0-9]{3}/day[0-2][0-9]$ ]]; then
|
|
|
|
YR=${PWD:0:4}
|
|
|
|
DY=${PWD:5:5}
|
|
|
|
DY=${DY/day0/}
|
|
|
|
DY=${DY/day/}
|
|
|
|
fi
|
2023-12-07 16:41:03 +00:00
|
|
|
if [[ ! -d "$AOCROOT/$YR/day$DIRDY" ]]; then
|
|
|
|
mkdir "$AOCROOT/$YR/day$DIRDY"
|
|
|
|
fi
|
|
|
|
cd "$AOCROOT/$YR/day$DIRDY"
|
2023-12-06 14:59:56 +00:00
|
|
|
if [[ -f "problem" ]]; then
|
|
|
|
echo "Found problem file."
|
|
|
|
if [[ $1 != "-f" ]]; then
|
|
|
|
# Check if the file already exists
|
|
|
|
echo "Not forcing overwrite."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Remove any zero padding from day
|
|
|
|
DY=$(echo "$CURRDAY"|awk '$0*=1')
|
|
|
|
echo "Getting problem at $CURRYEAR/day/$DY"
|
2023-12-07 16:41:03 +00:00
|
|
|
elinks -dump https://adventofcode.com/$CURRYEAR/day/$DY > problem
|
2023-12-06 14:59:56 +00:00
|
|
|
vim problem
|
|
|
|
}
|
|
|
|
|
2023-12-07 16:41:03 +00:00
|
|
|
getinput() {
|
|
|
|
YR=$CURRYEAR
|
|
|
|
DY=$CURRDAY
|
|
|
|
DIRDY=$CURRDAY
|
|
|
|
|
|
|
|
PWD=$(pwd)
|
|
|
|
PWD=${PWD#$AOCROOT/}
|
|
|
|
if [[ "$PWD" =~ ^[1-9][0-9]{3}/day[0-2][0-9]$ ]]; then
|
|
|
|
YR=${PWD:0:4}
|
|
|
|
DY=${PWD:5:5}
|
|
|
|
DY=${DY/day0/}
|
|
|
|
DY=${DY/day/}
|
|
|
|
fi
|
|
|
|
if [[ ! -d "$AOCROOT/$YR/day$DIRDY" ]]; then
|
|
|
|
mkdir "$AOCROOT/$YR/day$DIRDY"
|
|
|
|
fi
|
|
|
|
cd "$AOCROOT/$YR/day$DIRDY"
|
|
|
|
if [[ -f "input" ]]; then
|
|
|
|
echo "Found input file."
|
|
|
|
if [[ $1 != "-f" ]]; then
|
|
|
|
# Check if the file already exists
|
|
|
|
echo "Not forcing overwrite."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Remove any zero padding from day
|
|
|
|
DY=$(echo "$CURRDAY"|awk '$0*=1')
|
|
|
|
echo "Getting input for $CURRYEAR/day/$DY"
|
|
|
|
echo "https://adventofcode.com/$CURRYEAR/day/$DY/input"
|
|
|
|
echo "session=$(getsessiontoken)"
|
|
|
|
curl --cookie "session=$(getsessiontoken)" https://adventofcode.com/$CURRYEAR/day/$DY/input > input
|
|
|
|
# elinks -dump https://adventofcode.com/$CURRYEAR/day/$DY/input > input
|
|
|
|
# elinks -dump https://adventofcode.com/$CURRYEAR/day/$DY/input
|
|
|
|
}
|
|
|
|
|
2023-12-06 14:59:56 +00:00
|
|
|
getsessiontoken() {
|
|
|
|
FULLCOOKIE=$(grep "adventofcode" $HOME/.elinks/cookies)
|
|
|
|
if [[ ! -n "$FULLCOOKIE" ]]; then
|
|
|
|
echo "Error pulling elinks cookie"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo $FULLCOOKIE | cut -d" " -f2
|
|
|
|
}
|
|
|
|
|
|
|
|
help() {
|
|
|
|
echo "Usage: aoc [option]"
|
|
|
|
echo "Available Options:"
|
|
|
|
echo ""
|
2023-12-07 16:41:03 +00:00
|
|
|
echo " today - Echo the current day's directory, creating it if it doesn't exist"
|
|
|
|
echo ""
|
2023-12-06 14:59:56 +00:00
|
|
|
echo " getproblem - Retrieve the problem for the day associated with the current directory"
|
2023-12-06 15:13:56 +00:00
|
|
|
echo " If the current directory isn't a specific problem (\d\d\d\d/day\d\d/)"
|
|
|
|
echo " then it changes to today's directory, making it if needed"
|
2023-12-06 14:59:56 +00:00
|
|
|
echo ""
|
2023-12-07 16:41:03 +00:00
|
|
|
echo " getinput - Retrieve the input for the day associated with the current directory"
|
|
|
|
echo " If the current directory isn't a specific problem (\d\d\d\d/day\d\d/)"
|
|
|
|
echo " then it changes to today's directory, making it if needed"
|
|
|
|
echo ""
|
2023-12-06 14:59:56 +00:00
|
|
|
echo " getsessiontoken - Echo the session token from the elinks cookie file"
|
|
|
|
echo ""
|
2023-12-06 15:13:56 +00:00
|
|
|
echo " getsharelink - Get the repo remote path for the main.go file in the current directory"
|
|
|
|
echo " If the current directory isn't a specific problem (\d\d\d\d/day\d\d/)"
|
|
|
|
echo " then it uses today's directory"
|
|
|
|
echo ""
|
2023-12-06 14:59:56 +00:00
|
|
|
echo " help - Display this message"
|
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
|
|
|
|
case $1 in
|
2023-12-07 16:41:03 +00:00
|
|
|
"today")
|
|
|
|
today
|
|
|
|
;;
|
2023-12-06 14:59:56 +00:00
|
|
|
"getproblem")
|
2023-12-07 16:41:03 +00:00
|
|
|
getproblem
|
|
|
|
;;
|
|
|
|
"getinput")
|
|
|
|
getinput
|
2023-12-06 14:59:56 +00:00
|
|
|
;;
|
|
|
|
"getsessiontoken")
|
|
|
|
getsessiontoken
|
|
|
|
;;
|
2023-12-06 15:13:56 +00:00
|
|
|
"getsharelink")
|
|
|
|
getsharelink
|
|
|
|
;;
|
2023-12-06 14:59:56 +00:00
|
|
|
*)
|
|
|
|
help
|
|
|
|
;;
|
|
|
|
esac
|