-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_resolver.clj
54 lines (44 loc) · 1.05 KB
/
file_resolver.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
(ns image-x.file-resolver
(:require [cheshire.core :as cs]
[clojure.data.csv :as csv]
[clojure.java.io :as io]
[clojure.edn :as edn]))
(defn- tap [v] (do (println v) v))
(defn- path->string [path]
(-> path
io/file
slurp))
(defn from-json->list-uris
"Convert a json file to a list of uris."
[path]
(-> path
path->string
cs/parse-string
clojure.walk/keywordize-keys
:uris))
(defn from-edn->list-uris
"Convert a edn file to a list of uris."
[path]
(-> path
path->string
edn/read-string
:uris))
(defn from-csv->list-uris
"Convert a csv file to a list of uris. each line on file must be an uri."
[path]
(-> path
io/reader
csv/read-csv
vec
flatten
vec))
(comment
(from-csv->list-uris "resources/images.csv")
(from-edn->list-uris "resources/images.edn")
(from-json->list-uris "resources/images.json")
(-> "resources/images.json"
io/file
slurp
cs/parse-string
clojure.walk/keywordize-keys
:uris))