Skip to content

Instantly share code, notes, and snippets.

@zcaudate
Created February 14, 2015 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zcaudate/b5af1b1b7d71eb1575e0 to your computer and use it in GitHub Desktop.
Save zcaudate/b5af1b1b7d71eb1575e0 to your computer and use it in GitHub Desktop.
usage statistics for clojars
(import [bs4 [BeautifulSoup]]
[operator [itemgetter]]
requests)
(defn project-links [username]
(let [[url (+ "https://clojars.org/users/" username)]
[res (requests.get url)]
[soup (BeautifulSoup res.text)]
[links (-> (soup.find "h1")
(.find-next "h1")
(.find-next)
(.find-all "a"))]]
(list-comp (l.get "href") [l links])))
(defn project-stats [link]
(let [[res (requests.get (+ "https://clojars.org" link))]
[soup (BeautifulSoup res.text)]
[name (. (-> (apply soup.find [] {"class" "light-article"})
(.find "h1"))
text)]
[version (. (-> (apply soup.find [] {"id" "versions"})
(.find "a"))
text)]
[dl-html (-> (apply soup.find [] {"id" "jar-info-bar"})
(.find-all "li"))]
[dl-total (-> (. dl-html [1] text) (slice 0 -10) float int)]
[dl-version (-> (. dl-html [2] text) (slice 0 -13) float int)]
[output [name version dl-total dl-version]]]
(print output)
output))
(defn all-project-stats [username]
(let [[projects (project-links username)]
[stats (list-comp (project-stats link)
(link projects))]]
stats))
(comment
(def my-stats (all-project-stats "zcaudate"))
(apply sorted [my-stats] {"key" (itemgetter 2 3) "reverse" true}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment