Skip to content

Instantly share code, notes, and snippets.

@rbf
Last active August 29, 2015 14:18
Show Gist options
  • Save rbf/dccd50e7bcfce45ba5a3 to your computer and use it in GitHub Desktop.
Save rbf/dccd50e7bcfce45ba5a3 to your computer and use it in GitHub Desktop.
Get a list of the most played artists in La Planete Bleue radio show. Clojure version of https://gist.github.com/st/0c8512f916b944a3a23d.

Assuming you are on a *nix system with lein installed, you can run this gist with following command on a clean directory:

curl -sSLOO https://gist.github.com/rbf/dccd50e7bcfce45ba5a3/raw/{project,core}.clj && mkdir src && mv core.clj src/ && time lein run

This command will download both files below and begin the parsing of all broadcasted shows to finally list the 10 most played artitst. Please allow some 1.5-ish minutes to run, since there are more than 850 shows to date.

To get the list of the most played artist between the show number x and the show number y, execute lein run x y.

(ns core
"See project description."
(:require [net.cgrand.enlive-html :as html]
[net.cgrand.jsoup :as jsoup]))
(html/set-ns-parser! jsoup/parser)
(def most-recent-show
(->> (-> "http://www.laplanetebleue.com/emissions.php"
java.net.URL.
html/html-resource
(html/select-nodes* [:select :option]))
(map #(-> % :attrs :value not-empty (or "-1") Integer/parseInt))
(apply max)))
(defn most-played-artists
[start-show end-show]
{:pre [(number? start-show)
(number? end-show)
(<= 1 start-show end-show most-recent-show)]}
(printf "Most played artists between the shows %d and %d:\n" start-show end-show)
(->> end-show
inc
(range start-show)
(mapcat #(-> (str "http://www.laplanetebleue.com/emission-" %)
java.net.URL.
html/html-resource
(html/select-nodes* [[:a (html/attr-contains :href "artiste=")] html/text-node])))
frequencies
(sort-by first)
reverse
(sort-by second)
reverse
(take 10)
(map #(apply printf " - %s played %s times\n" %))
dorun))
(defn -main
[& [arg1 arg2]]
(let [start-show (if (not-empty arg1) (Integer/parseInt arg1) 1)
end-show (if (not-empty arg2) (Integer/parseInt arg2) most-recent-show)]
(time (most-played-artists start-show end-show))))
(defproject rbf.gist.lpb "0.1"
:description "Get a list of the most played artists in La Planete Bleue radio show."
:url "http://gist.github.com/rbf"
:license {:name "MIT"
:url "http://opensource.org/licenses/MIT"}
:dependencies [[org.clojure/clojure "1.6.0"]
[enlive "1.1.5"]]
:repl-options {:init-ns core}
:main core
:source-path "src")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment