Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns melody.core
- (:require [clj-http.client :as client]
- [net.cgrand.enlive-html]))
- (def harmony-url "https://harmony.wl.k12.in.us")
- (def cookies (ref nil))
- (def user-id (ref nil))
- (defn authenticate [username password]
- (let [response (client/post (str harmony-url "/student.nsf/names.nsf?Login")
- {:form-params {:username username
- :password password
- :redirectto "/student.nsf/LoginMobile?OpenAgent"}})]
- (dosync
- (ref-set cookies (:cookies response)))
- response))
- (defn register-with-agent [username password]
- (let [response (client/get (str harmony-url "/student.nsf/LoginMobile?OpenAgent")
- (authenticate username password))]
- (dosync
- (ref-set user-id ((re-matches #".*id=(.*)"
- (last (:trace-redirects response))) 1)))
- response))
- (defn progress-report []
- (client/get
- (str
- "https://harmony.wl.k12.in.us/student.nsf/mProgressReport?OpenAgent&id="
- @user-id)
- {:cookies @cookies}))
- (defn resource []
- (register-with-agent "username" "password")
- (net.cgrand.enlive-html/html-resource (java.io.StringReader.
- (:body (progress-report)))))
- (defn progress []
- (map (fn [s] {:course-title
- (first
- (:content
- (first
- (:content
- (first
- (:content s)))))),
- :percent
- (first (:content (second (:content s))))
- :grade
- (first (:content (nth (:content s) 2)))})
- (rest (select (resource) [:.c2 :table :tr]))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement