Skip to content

Instantly share code, notes, and snippets.

@luxbock luxbock/core.clj
Created Sep 21, 2014

Embed
What would you like to do?
lein-plz-nicknames
(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
You can’t perform that action at this time.