Fix erroneous JSON data loading #5
|
@ -6,21 +6,21 @@
|
||||||
[clojure.data.json :as json]
|
[clojure.data.json :as json]
|
||||||
[clj-yaml.core :as yaml]))
|
[clj-yaml.core :as yaml]))
|
||||||
|
|
||||||
(defn json-data-reader [key value]
|
(defn setify-vals [x]
|
||||||
(if (= key :games)
|
(reduce #(assoc %1
|
||||||
(into (empty value)
|
(first %2)
|
||||||
(map #(hash-map (first %)
|
(set (second %2)))
|
||||||
(set (second %)))
|
{} x))
|
||||||
value))
|
|
||||||
value))
|
(defn process-json [x]
|
||||||
|
(update x :games setify-vals))
|
||||||
|
|
||||||
(defn load-state [f]
|
(defn load-state [f]
|
||||||
(try
|
(process-json
|
||||||
(with-open [datafile (clojure.java.io/reader f)]
|
(try
|
||||||
(json/read datafile
|
(with-open [datafile (clojure.java.io/reader f)]
|
||||||
:value-fn json-data-reader
|
(json/read datafile :key-fn keyword))
|
||||||
:key-fn keyword))
|
(catch Exception e nil))))
|
||||||
(catch Exception e nil)))
|
|
||||||
|
|
||||||
(defn save-state [f data]
|
(defn save-state [f data]
|
||||||
(try
|
(try
|
||||||
|
|
Loading…
Reference in New Issue