 (ns restaurant-inspections-api.tasks
   (:require [clj-time.core :as t]
             [clj-time.format :as f]
+            [clojure.set :as set]
             [clj-time.periodic :refer [periodic-seq]]
             [clojure-csv.core :as csv]
-            [org.httpkit.client :as http]
             [chime :refer [chime-at]]
             [restaurant-inspections-api.environment :as env]
             [clojure.java.jdbc :as db]

         (parse (slurp file)))
       csv-files))

(defn process-load-data
  "load and read the CSV, compare and insert the new ones on DB"
  []
  (let [csv-files (env/get-csv-files)
        inspections (download csv-files)]
    (mapv (fn [rows]
            (println "Inserting data for District " (:district (first rows)))
            (println "District " (:district (first rows))
                     " - Saved Rows: " (count (insert-data! rows))))  ; TODO: before insert, check existing rows
          inspections)))

(defn load-api-data
  "schedules the load process"

                  (withTime 4 0 0 0))                       ; Scheduled to run every day at 4 am
                  (-> 1 t/days)))
            (fn [time]
              (prn "Starting load data task" time)
              (process-load-data))))