 (defn get-tags [exercise]
   (html/text (nth exercise 8)))
 
-(defn insert [uid exercise]
+(defn insert [login-id exercise]
   (mc/insert "exercise"
                   {:date (get-timestamp exercise),
-                   :user uid,
-                   :sport 1,
+                   :user login-id,
+                   :sport (get-or-create-sport exercise),
                    :duration (get-duration exercise),
                    :distance (get-distance exercise),
                    :avghr (get-avghr exercise),

  (html/html-resource (java.io.FileReader. filename)))

(defn get-exercises [imported-html]
  (rest (html/select imported-html [:tr])))

(defn is-ex? [ex-html]

    (.getTime (java.util.Date. (- (nth date-array 2) 1900) 
                               (+ 1 (second date-array)) 
                               (first date-array) 12 0))))
(defn get-or-create-login-id [login-id]
    (let [_login-id (mc/find-one "onuser" {:_id login-id})]
      (if (= nil _login-id) (mc/insert "onuser" {:_id login-id}))
      login-id))

(defn get-timestamp [exercise]
  (convert-to-timestamp (html/text (nth exercise 0))))

(defn get-heading [exercise] (html/text (nth exercise 1)))

(defn get-or-create-sport [exercise]
  "XXX: not thread safe!??"
  (let [sport-id (html/text (nth exercise 2))
        _sport-id (mc/find-one "onsport" {:_id sport-id})]
    (if (= nil _sport-id) (mc/insert "onsport" {:_id sport-id}))
    sport-id))

(defn get-report [exercise] 
  "Emits the html in report and joins all strings in it."
