Fix erroneous JSON data loading #5

Merged
seabass merged 1 commits from seabass/matchbot:fix-json-loading into master 2022-03-29 21:15:14 +02:00
1 changed files with 13 additions and 13 deletions

View File

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