     (kdb/postgres settings)))
 
 
-(defn mongo-db [mongo-url]
-  (let [params  {}
-        con     (mg/connect params)]
-    (mg/get-db con "polismath")))
-
 
 (defn split-by-conv [votes]
   (reduce

(ns polismath.poller
  (:use clojure.pprint
        polismath.conversation
        polismath.named-matrix
        polismath.utils
        polismath.pca)
  (:require [korma.db :as kdb]
            [korma.core :as ko]
            [clojure.java.jdbc :as sql]
            [monger.core :as mg]
            [monger.collection :as mg.col]
            [environ.core :as env]))


(defn heroku-db-spec [db-uri]
  (let [[_ user password host port db] (re-matches #"postgres://(?:(.+):(.*)@)?([^:]+)(?::(\d+))?/(.+)" db-uri)

            new-votes (poll pg-spec @last-timestamp)
            split-votes (split-by-conv new-votes)]
        (doseq [[zid votes] split-votes]
          (let [lastVoteTimestamp (:created (last votes))]
            (swap! conversations
              (fn [convs]
                (assoc convs zid
                    (try
                      (small-conv-update {:conv (or (convs zid)
                                              {:rating-mat (named-matrix)})
                                      :votes votes
                                      :opts {}})
                        (catch Exception e (println "exception when processing zid: " zid))))))
                
            ;(upsert-results pg-spec 1001 1 "foo")
            (println "zid: " zid)
            (println "time: " (System/currentTimeMillis))
            (println "\n\n")
            (println (generate-string (prep-for-uploading (@conversations zid))))
            ; (debug-repl)
            (println 
              (mongo-upsert-results
                zid
                lastVoteTimestamp
                (generate-string
                  (prep-for-uploading
                    (@conversations zid)))))
        (swap! last-timestamp (fn [_] (:created (last new-votes))))
      ))))))
