Created
September 21, 2014 12:00
-
-
Save luxbock/6327ae7e4fd3ff8c9df5 to your computer and use it in GitHub Desktop.
lein-plz-nicknames
This file contains hidden or 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
| (ns lein-plz-nicknames | |
| "Tiny script to check for additional projects discovered by crawling | |
| crossclj.info and filtering for the popularity of the project." | |
| (:require [me.raynes.laser :as l] | |
| [clojure.string :as str] | |
| [leiningen.plz :refer [fallback-nicknames]])) | |
| (def prj-from-crossclj | |
| "Fetches a list of projects from crossclj.info" | |
| (apply str | |
| (drop 9 | |
| (-> (slurp "http://crossclj.info/all.html?sort=r") | |
| l/parse | |
| (l/select (l/and (l/id= "data") (l/element= :script))) | |
| first :content first)))) | |
| (defn get-prj-parts [s] | |
| (partition 6 (str/split s #"\|"))) | |
| (defn filter-by-popularity | |
| [prj-parts popularity] | |
| (filter #(>= (Integer/parseInt (first %)) popularity) prj-parts)) | |
| (defn just-prj-path [parts] (map second parts)) | |
| (defn prj->nickname | |
| "Takes a list of project paths and returns a map of each project to | |
| an appropriate shorthand nickaname." | |
| [paths] | |
| (reduce merge | |
| (sorted-map) | |
| (map | |
| (fn [p] | |
| (let [s (symbol p) | |
| parts (str/split p #"/") | |
| nn (if (> (count parts) 1) (last parts) (first parts))] | |
| {(symbol p) #{nn}})) | |
| paths))) | |
| (defn exclude-existing | |
| [prj-map] | |
| (into (sorted-map) | |
| (remove #(contains? fallback-nicknames (key %)) prj-map))) | |
| (defn new-nicknames [popularity] | |
| (-> prj-from-crossclj | |
| get-prj-parts | |
| (filter-by-popularity popularity) | |
| just-prj-path | |
| prj->nickname)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment