From 8079694bd5ab49d1a75247185ff2f6cea9f370c7 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Sun, 4 Dec 2022 16:23:27 +0000 Subject: newday --- .gitignore | 2 ++ README.textile | 6 ++++++ newday | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 .gitignore create mode 100755 newday diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f80fbab --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +sessionToken +*.swp diff --git a/README.textile b/README.textile index 6663fbc..4ab3acf 100644 --- a/README.textile +++ b/README.textile @@ -1,5 +1,11 @@ h1. Advent of Code 2022 +h2. newday + +p. Put your session cookie in @sessionToken@. + +p. Run @./newday@ to set up a new day. + h2. Running bc. $ cd dayXX diff --git a/newday b/newday new file mode 100755 index 0000000..7a3258b --- /dev/null +++ b/newday @@ -0,0 +1,40 @@ +#!/usr/bin/env ruby + +require 'open-uri' +require 'nokogiri' + +sessionToken = File.read("sessionToken").strip + +now = Time.now +year = now.year +day = now.day + +print "Set up year #{year} day #{day} [/y.*/i]? " +if gets.strip.downcase[0] != ?y + print "Year: " + year = gets.to_i + print "Day: " + day = gets.to_i +end + +if File.directory?("day%02d" % day) + $stderr.puts "Day #{day} already set up" + exit 1 +end + +baseUrl = "https://adventofcode.com/#{year}/day/#{day}" + +dayPage = Nokogiri::HTML(URI.open(baseUrl, "Cookie" => "session=#{sessionToken}")) + +testData = dayPage.css('body > main > article.day-desc > pre > code')[0].content +inputData = URI.open("#{baseUrl}/input", "Cookie" => "session=#{sessionToken}").read + +baseDir = "day%02d" % day +Dir.mkdir(baseDir) + +File.open(File.join(baseDir, "test"), ?w) do |f| + f.print(testData) +end +File.open(File.join(baseDir, "input"), ?w) do |f| + f.print(inputData) +end -- cgit v1.2.1