Skip to content

Instantly share code, notes, and snippets.

@bysse
Last active December 3, 2020 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bysse/e52980dbc4a4ad293f6a78e6367f5feb to your computer and use it in GitHub Desktop.
Save bysse/e52980dbc4a4ad293f6a78e6367f5feb to your computer and use it in GitHub Desktop.
AoC get input script
#!/bin/bash
if [ -z "$1" ]; then
echo "Missing day number as argument!"
exit 1
fi
SESSION=""
DAY="$1"
YEAR="2020"
URL="https://adventofcode.com/$YEAR/day/$DAY/input"
FILE=input$DAY.txt
CODE=day_$DAY.py
CODE_TEMPLATE=day_template.py
if [ -z "$SESSION" ]; then
echo "No session set"
exit 1
fi
if [ ! -e $FILE ]; then
echo "# Downloading file for day $DAY"
curl -s --cookie "session=$SESSION" $URL > $FILE
else
echo "# File for day $DAY already exists"
fi
if [ ! -e $CODE ]; then
echo "# Generating template file $CODE"
cp $CODE_TEMPLATE $CODE
sed -i "s/@INPUT_FILE@/$FILE/g" $CODE
fi
echo "#"
echo "# Size: " $(stat --printf="%s" $FILE)
echo "# Lines: " $(cat $FILE | wc -l)
echo "#"
echo "# Sample data:"
head $FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment