Prints a JSON map of the languages used in your repos, sorted by frequency in descending order.
lein run -m gh-languages # | hicat
(ns gh-languages | |
(:require [cheshire.core :as json] | |
[clojure.pprint :refer [pprint]] | |
[environ.core :refer [env]] | |
[org.httpkit.client :as http])) | |
(def my-repos (str "https://api.github.com/users/" (env :gh-user) "/repos")) | |
(def options {:basic-auth [(env :gh-access-token) "x-oauth-basic"]}) | |
(defn sort-by-val [m] | |
(let [>val #(compare ((juxt m identity) %2) ((juxt m identity) %1))] | |
(into (sorted-map-by >val) m))) | |
(defn -main [& args] | |
(-> (:body @(http/get my-repos options)) | |
(json/parse-string true) | |
(->> (remove (comp #{"https://github.com/yurrriq/homebrew"} :html_url)) | |
(map :languages_url) | |
(map #(json/parse-string (:body @(http/get % options)))) | |
(apply merge-with +)) | |
sort-by-val | |
(json/generate-string {:pretty true}) | |
println)) |
{:user {:dependencies [[cheshire "5.4.0"] | |
[environ "1.0.0"] | |
[http-kit "2.1.19"]] | |
:plugins [[lein-environ "1.0.0"]] | |
:env {:gh-user "YOUR-GITHUB-USERNAME" | |
:gh-access-token "YOUR-ACCESS-TOKEN"}}} |