Last active
April 12, 2017 19:27
-
-
Save mjamesruggiero/9a04d5e5f4b561c667435f8b31da6ef7 to your computer and use it in GitHub Desktop.
Get unsolved exercises from your KA profile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; assumes that you have a JSON file | |
;; corresponding to /api/v1/user/exercises?username=<your-username> | |
(ns khan.core | |
(:require [clojure.data.csv :as csv] | |
[clojure.java.io :as io] | |
[clojure.data.json :as json])) | |
(defn get-json | |
[filepath] | |
(with-open [in-file (io/reader filepath)] | |
(doall | |
(json/read in-file)))) | |
(def exercises | |
(get-json | |
"/Users/michaelruggiero/code/mr/singh/mr-khan.json")) | |
(defn get-stats [ex] | |
(let [ex-name (get ex "exercise") | |
mastered (get-in ex ["exercise_progress" "mastered"]) | |
ka "https://www.khanacademy.org" | |
url (str ka (get-in ex ["exercise_model" "relative_url"]))] | |
[ex-name url mastered])) | |
(defn unsolved | |
[exercises] | |
(filter (fn [elem] (= false (nth elem 2))) | |
(map get-stats exercises))) | |
(let [headers ["exercise" "url" "solved?"] | |
rows (unsolved exercises)] | |
(with-open [file (io/writer "/Users/michaelruggiero/Desktop/khan_academy_unsolved_2017_04_12.csv")] | |
(csv/write-csv file (cons headers rows))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment