Add correct day7pt1
[adventofcode2019.git] / src / adventofcode2019 / lib.clj
index 834893c31815f6ccd28447ef4cc3f1d1ccec7b0d..2699439f649085f7769e1b9154858ebd8e09f7d9 100644 (file)
@@ -1,6 +1,7 @@
 (ns adventofcode2019.lib
     [:require [clojure.string :as str]
-              [clojure.java.io :as io]])
+              [clojure.java.io :as io]
+              [clojure.java.shell :refer [sh]]])
 
 (defn get-list-from-file
   ([file-name]
@@ -8,14 +9,37 @@
   ([file-name split-regex]
     (str/split (str/trim (slurp file-name)) split-regex)))
 
+(def parse-int
+  #(Integer/parseInt %))
+
 (defmacro input-file []
   (let [bottom-ns (last (str/split (str *ns*) #"\."))]
     (str "resources/" bottom-ns)))
 
-(def parse-int
-  #(Integer/parseInt %))
-
 (def part1 
   #(println (str "Part 1: " %)))
 (def part2 
   #(println (str "Part 2: " %)))
+
+;; FIXME: this is still broken but i give up for now
+; (defn --input-file [for-ns]
+;   (let [bottom-ns (last (str/split for-ns #"\."))
+;         input-url "https://adventofcode.com/2019/day/%d/input"
+;         day-url (->> bottom-ns
+;                      (drop 3)
+;                      (str/join)
+;                      (parse-int)
+;                      (format input-url))
+;         token (str/trim (slurp (io/resource "token")))
+;         res-dir (-> (io/resource "token") 
+;                     (.getPath)
+;                     (str/replace "token" bottom-ns))
+;         cmd ["curl" "-s" "-b" 
+;              (format "\"session=%s\"" token) 
+;              day-url ">" res-dir]]
+;     (if-let [input (io/resource bottom-ns)]
+;             input
+;             (do (apply sh cmd) nil))))
+
+; (defmacro input-file []
+;   (--input-file (str *ns*)))