SHARE
TWEET

Untitled

jkdufair Mar 3rd, 2012 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns melody.core
  2.   (:require [clj-http.client :as client]
  3.             [net.cgrand.enlive-html]))
  4.  
  5. (def harmony-url "https://harmony.wl.k12.in.us")
  6.  
  7. (def cookies (ref nil))
  8.  
  9. (def user-id (ref nil))
  10.  
  11. (defn authenticate [username password]
  12.    (let [response (client/post (str harmony-url "/student.nsf/names.nsf?Login")
  13.                  {:form-params {:username username
  14.                                 :password password
  15.                                 :redirectto "/student.nsf/LoginMobile?OpenAgent"}})]
  16.      (dosync
  17.       (ref-set cookies (:cookies response)))
  18.      response))
  19.  
  20. (defn register-with-agent [username password]
  21.   (let [response (client/get (str harmony-url "/student.nsf/LoginMobile?OpenAgent")
  22.                              (authenticate username password))]
  23.     (dosync
  24.      (ref-set user-id ((re-matches #".*id=(.*)"
  25.                                    (last (:trace-redirects response))) 1)))
  26.     response))
  27.  
  28. (defn progress-report []
  29.   (client/get
  30.    (str
  31.     "https://harmony.wl.k12.in.us/student.nsf/mProgressReport?OpenAgent&id="
  32.     @user-id)
  33.    {:cookies @cookies}))
  34.  
  35. (defn resource []
  36.   (register-with-agent "username" "password")
  37.   (net.cgrand.enlive-html/html-resource (java.io.StringReader.
  38.                                          (:body (progress-report)))))
  39.  
  40. (defn progress []
  41.   (map (fn [s] {:course-title
  42.                 (first
  43.                  (:content
  44.                   (first
  45.                    (:content
  46.                     (first
  47.                      (:content s)))))),
  48.                 :percent
  49.                 (first (:content (second (:content s))))
  50.                 :grade
  51.                 (first (:content (nth (:content s) 2)))})
  52.        (rest (select (resource) [:.c2 :table :tr]))))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top