Created
August 10, 2017 23:51
-
-
Save derveloper/7ba9040806085b8268e821656c8a84d1 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env boot | |
(set-env! :dependencies '[[org.clojure/clojure "1.8.0"] | |
[http-kit "2.2.0"] | |
[org.clojure/data.json "0.2.6"]]) | |
(require '[org.httpkit.client :as http]) | |
(require '[clojure.data.json :as json]) | |
(require '[boot.cli :refer [defclifn]]) | |
(defn fetch-gh-stars | |
[username] | |
@(http/get (str "https://api.github.com/users/" username "/starred"))) | |
(defn to-json | |
[response] | |
(json/read-str (:body response))) | |
(defn extract-repo-info [json] | |
(mapv #(hash-map :name (get % "full_name") :language (get % "language")) json)) | |
(defn fetch-starred-repos | |
[username] | |
(-> | |
(fetch-gh-stars username) | |
to-json | |
extract-repo-info)) | |
(defn languages-of [repos] | |
(remove nil? (distinct (map #(get % :language) repos)))) | |
(defn fetch-starred-repos-for | |
[u1 u2] | |
(let [first (future (fetch-starred-repos u1)) | |
second (future (fetch-starred-repos u2))] | |
{:first {:repos @first | |
:name u1 | |
:count (count @first) | |
:languages (languages-of @first)} | |
:second {:repos @second | |
:name u2 | |
:count (count @second) | |
:languages (languages-of @second)} | |
:common (let [repos (vec (clojure.set/intersection (set @first) (set @second))) | |
languages (vec | |
(clojure.set/intersection (set (languages-of @first)) | |
(set (languages-of @second))))] | |
{:repos repos | |
:languages languages | |
:repo-count (count repos) | |
:languages-count (count languages)})})) | |
(defclifn -main | |
[] | |
(println (fetch-starred-repos-for "derveloper" "bfncs"))) |
Same shit with recursive fetching of all pages in JS: https://gist.github.com/bfncs/a393e410e7fec51c3d1c72e0bc1f9a30
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
clojure ftw ๐๐๐๐๐