Browse Source

wrote script to facilitate building up a library of images

Brandon Wong 1 year ago
parent
commit
46d51cad3d
4 changed files with 105 additions and 31 deletions
  1. 4 6
      README.md
  2. 50 0
      curator.clj
  3. 25 0
      library.edn
  4. 26 25
      src/lineup/db.cljs

+ 4 - 6
README.md

@@ -3,18 +3,16 @@
 A visual schedule builder for kids.
 
 TODO:
-- edit schedule
-  - make a list, choosing from a (text-searchable) library of images/tasks
-    - use modal-panel component and typeahead component
 - name the schedule/track
-- add little numbers to each box
-- green outline + check mark
 - save state (preserve across refresh)
+  - need server
+  - use localstorage ??
 - (saveable) preset schedules (in edit menu)
 - (optional) multiple simultaneous schedules (ex: one for each kid, or general vs specific)
 - (optional) split decision tracks (conditions)
 - (saveable) make-your-own tasks
-- use localstorage ??
+  - incorporate an internet search in the editor?
+  - crowdsource images??
 
 library (each category has a representative picture/task, as does each sub-item):
 - bedtime routine

+ 50 - 0
curator.clj

@@ -0,0 +1,50 @@
+#!/usr/bin/env bb
+
+(require '[clojure.java.io :as io]
+         '[clojure.string :as string]
+         '[clojure.pprint :refer [pprint]])
+
+(def exceptions
+  #{"index.html"
+    "styles.css"
+    "js"
+    "clapping.gif"
+    "go.png"
+    "clapping.png"
+    "vendor"})
+
+(let [foldername "./resources/public"
+      folder (io/file foldername)
+      existing-filename "./library.edn"
+      existing (try
+                 (-> existing-filename
+                     (slurp)
+                     (read-string))
+                 (catch Exception _ []))
+      existing-files (->> existing
+                          (map :image)
+                          (set))
+      highest-index (or (some->> existing
+                                 (map :id)
+                                 (not-empty)
+                                 (apply max)
+                                 (inc))
+                        1)]
+  (if (.isDirectory folder)
+    (->> (.list folder)
+         (remove exceptions)
+         (remove existing-files)
+         (map-indexed (fn [ind file]
+                        {:id (+ highest-index ind)
+                         :name (-> file
+                                   (string/replace #"\.[^\.]*$" "")
+                                   (string/replace #"[-\._]" " "))
+                         :image file}))
+         (concat existing)
+         (vec)
+         ((fn [new-data]
+            (with-open [writer (io/writer existing-filename)]
+              (pprint new-data writer))
+            (println "wrote to" existing-filename))))
+    (println "Folder not found. Make sure to run this script from its containing folder.")))
+

+ 25 - 0
library.edn

@@ -0,0 +1,25 @@
+[{:id 1,
+  :name "sleep",
+  :categories ["bedtime" "naping"],
+  :keywords ["bed" "nap"],
+  :image "sleep.png"}
+ {:id 2,
+  :name "eat",
+  :categories ["eating"],
+  :keywords ["meal" "food" "chopsticks"],
+  :image "eating1.png"}
+ {:id 3,
+  :name "eat",
+  :categories ["eating"],
+  :keywords ["meal" "food" "spaghetti"],
+  :image "eating2.png"}
+ {:id 4,
+  :name "go to school",
+  :categories ["school"],
+  :keywords ["class"],
+  :image "school.png"}
+ {:id 5,
+  :name "brush teeth",
+  :categories ["bedtime"],
+  :keywords ["bedtime" "routine"],
+  :image "teeth-brushing.png"}]

+ 26 - 25
src/lineup/db.cljs

@@ -5,28 +5,29 @@
    :selecting nil
    :schedule {:tasks [{:ref 2} {:ref 5} {:ref 4} {:ref 5} {:ref 1}]}
 
-   :library [{:id 1
-              :name "sleep"
-              :categories ["bedtime" "naping"]
-              :keywords ["bed" "nap"]
-              :image "sleep.png"}
-             {:id 2
-              :name "eat"
-              :categories ["eating"]
-              :keywords ["meal" "food" "chopsticks"]
-              :image "eating1.png"}
-             {:id 3
-              :name "eat"
-              :categories ["eating"]
-              :keywords ["meal" "food" "spaghetti"]
-              :image "eating2.png"}
-             {:id 4
-              :name "go to school"
-              :categories ["school"]
-              :keywords ["class"]
-              :image "school.png"}
-             {:id 5
-              :name "brush teeth"
-              :categories ["bedtime"]
-              :keywords ["bedtime" "routine"]
-              :image "teeth-brushing.png"}]})
+   :library
+   [{:id 1
+     :name "sleep"
+     :categories ["bedtime" "naping"]
+     :keywords ["bed" "nap"]
+     :image "sleep.png"}
+    {:id 2
+     :name "eat"
+     :categories ["eating"]
+     :keywords ["meal" "food" "chopsticks"]
+     :image "eating1.png"}
+    {:id 3
+     :name "eat"
+     :categories ["eating"]
+     :keywords ["meal" "food" "spaghetti"]
+     :image "eating2.png"}
+    {:id 4
+     :name "go to school"
+     :categories ["school"]
+     :keywords ["class"]
+     :image "school.png"}
+    {:id 5
+     :name "brush teeth"
+     :categories ["bedtime"]
+     :keywords ["bedtime" "routine"]
+     :image "teeth-brushing.png"}]})