Last active
December 3, 2020 07:46
-
-
Save bysse/e52980dbc4a4ad293f6a78e6367f5feb to your computer and use it in GitHub Desktop.
AoC get input script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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