Skip to content
Go to file
Cannot retrieve contributors at this time
81 lines (69 sloc) 2.03 KB
(ns logic-introduction.fetch
(:refer-clojure :exclude [==])
(:use [ :only (json-str write-json read-json)])
(:use [clojure.core.logic]))
(defn url-to-process
"Output: url"
(== url ""))
(defn slurpo
"Input: url
Output: datastream"
[url datastream]
(project [url]
(== datastream (slurp url))))
(defn read-jsono
"Input: input
Output: output"
[input output]
(project [input]
(== output (read-json input))))
(defn fetch-data
"Output: fetched-data"
(fresh [url datastream]
(url-to-process url)
(slurpo url datastream)
(read-jsono datastream fetched-data)))
(defn process-data-header
"Input: header"
(matche [header]
(defn json-object-has-value
"Input: json-object, name
Output: value"
[json-object name value]
(project [json-object name]
(== [name value] (find json-object name))))
(defn process-json-object
"Input: json-object"
(fresh [date-value indicator-value temp]
(json-object-has-value json-object :date date-value)
(json-object-has-value json-object :value indicator-value)
(project [date-value indicator-value]
;; TODO probably have to wrap println
(== temp (println "Date: " date-value))
(== temp (println "Value: " indicator-value))
(== temp (println)))))
(defn process-data-contents
"Input: json"
(matche [json]
([[?json-object . ?rest]]
(process-json-object ?json-object)
(process-data-contents ?rest))))
(defn process-data
"Input: json"
(matche [json]
([[?header ?contents]]
(process-data-header ?header)
(process-data-contents ?contents))))
(defn fetch-and-process-data []
(run* [fetched-data]
(fetch-data fetched-data)
(process-data fetched-data)))
You can’t perform that action at this time.