             [taoensso.timbre :as timbre]
             [clojure.string :as str]
             [clojure.data :refer [diff]]
+            [clj-time.core :as t]
+            [clj-time.periodic :as p]
             [tictag.db :as db]
             [tictag.beeminder-matching :refer [match?]]
             [tictag.riemann :as riemann]))

    true)))

(defn update-datapoint! [auth-token user goal datapoint]
  (http/request {:url (format "https://www.beeminder.com/api/v1/users/%s/goals/%s/datapoints/%s.json"
                              user goal (:id datapoint))
                 :method :put
                 :query-params {:auth_token auth-token
                                :value (:value datapoint)}}))

(defn create-datapoint! [auth-token user goal datapoint]
  (http/request {:url (format "https://www.beeminder.com/api/v1/users/%s/goals/%s/datapoints.json"

  (when (:enabled? (:beeminder user))
    (when-let [goals (seq (db/get-goals db (:beeminder user)))]
      (tracef "goals are %s, getting rows" goals)
      (let [in-past-week? (past-week-days)
            rows          (filter #(in-past-week? (:local-day %))
                                  (db/get-pings-by-user (:db db) user))]
        (doseq [{:keys [goal/name goal/tags]} goals]
          (debugf "Syncing goal: %s with tags %s" name tags)
          (let [{:keys [username token]} (:beeminder user)
                days                     (days-matching-tag tags rows)
                existing-datapoints      (filter
                                          #(in-past-week? (:daystamp %))
                                          (datapoints
                                           (get-in
                                            user
                                            [:beeminder :token])
                                           username
                                           name))
                existing-map             (group-by :daystamp existing-datapoints)
                to-save                  (filter :value
                                                 (for [[daystamp value] days
