From e868ad937f9ef1cd169d5abec9002ee1271c406c Mon Sep 17 00:00:00 2001 From: zodac Date: Sun, 10 Dec 2023 22:09:27 +1300 Subject: [PATCH] Fixing create script to exclude HTTP code in input file --- advent-of-code-inputs | 2 +- create.sh | 40 +++++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/advent-of-code-inputs b/advent-of-code-inputs index 4f64cd7..cb5e146 160000 --- a/advent-of-code-inputs +++ b/advent-of-code-inputs @@ -1 +1 @@ -Subproject commit 4f64cd776b6061b14b64bbbbf1118689fcf4e389 +Subproject commit cb5e1463c22df989b74749fe4743545108bd8b6c diff --git a/create.sh b/create.sh index 84d1edb..9e0cff9 100644 --- a/create.sh +++ b/create.sh @@ -15,6 +15,7 @@ day="${2}" if [[ ${day} -lt 10 ]]; then day_long="0${day: -1}" + day="${day: -1}" else day_long="${day}" fi @@ -26,6 +27,7 @@ if [[ ! -d "./${year}" ]]; then exit 1 fi +# Input file echo -e "\t- Creating actual input file" if [[ -z "${AOC_COOKIE}" ]]; then echo -e "\t\tNo cookie set for AOC, cannot create actual input file" @@ -42,7 +44,7 @@ else exit 1; fi - echo "${output}" > "./advent-of-code-inputs/${year}/day${day_long}.txt" || exit 1 + echo "${output}" | head -n -1 > "./advent-of-code-inputs/${year}/day${day_long}.txt" || exit 1 cd ./advent-of-code-inputs || exit 1 git add "${year}/day${day_long}.txt" git commit --quiet -m "Adding input for ${year}, Day ${day}" @@ -50,33 +52,37 @@ else cd .. || exit 1 fi -echo -e "\t- Retrieving title" -title_output=$(curl \ - --user-agent "https://github.com/zodac/advent-of-code by zodac" \ - --silent \ - --write-out "%{http_code}" \ - "https://adventofcode.com/${year}/day/${day}") - -title_http_status_code=$(echo "${output}" | tail -1) -if [[ ${title_http_status_code} != "200" ]]; then - echo "Invalid response code for title ${http_status_code}" - exit 1; -fi - -title=$(echo "${title_output}" | grep '

' | awk '{split($0,a,"

")} END{print a[2]}' | awk '{split($0,a,"

")} END{print a[1]}' | cut -d ':' -f2 | cut -d '-' -f1 | awk '{$1=$1;print}') -sed -i -e "s|%TITLE%|${title}|g" "./${year}/src/main/java/me/zodac/advent/Day${day_long}.java" - +# Example input file echo -e "\t- Creating example input file" touch "./${year}/src/test/resources/day${day_long}.txt" +# Java source echo -e "\t- Creating Java source file" cp ./templates/Day.java "./${year}/src/main/java/me/zodac/advent/Day${day_long}.java" sed -i -e "s|%YEAR%|${year}|g" "./${year}/src/main/java/me/zodac/advent/Day${day_long}.java" sed -i -e "s|%DAY%|${day}|g" "./${year}/src/main/java/me/zodac/advent/Day${day_long}.java" sed -i -e "s|%DAY_LONG%|${day_long}|g" "./${year}/src/main/java/me/zodac/advent/Day${day_long}.java" +# Java test echo -e "\t- Creating Java test file" cp ./templates/DayTest.java "./${year}/src/test/java/me/zodac/advent/Day${day_long}Test.java" sed -i -e "s|%YEAR%|${year}|g" "./${year}/src/test/java/me/zodac/advent/Day${day_long}Test.java" sed -i -e "s|%DAY%|${day}|g" "./${year}/src/test/java/me/zodac/advent/Day${day_long}Test.java" sed -i -e "s|%DAY_LONG%|${day_long}|g" "./${year}/src/test/java/me/zodac/advent/Day${day_long}Test.java" + +# Title +echo -e "\t- Retrieving title" +title_output=$(curl \ + --user-agent "https://github.com/zodac/advent-of-code by zodac" \ + --silent \ + --write-out "%{http_code}" \ + "https://adventofcode.com/${year}/day/${day}") + +title_http_status_code=$(echo "${output}" | tail -1) +if [[ ${title_http_status_code} != "200" ]]; then + echo "Invalid response code for title ${http_status_code}" + exit 1; +fi + +title=$(echo "${title_output}" | head -n -1 | grep '

' | awk '{split($0,a,"

")} END{print a[2]}' | awk '{split($0,a,"

")} END{print a[1]}' | cut -d ':' -f2 | cut -d '-' -f1 | awk '{$1=$1;print}') +sed -i -e "s|%TITLE%|${title}|g" "./${year}/src/main/java/me/zodac/advent/Day${day_long}.java" \ No newline at end of file