Skip to content

Instantly share code, notes, and snippets.

@pbalduino
Last active August 29, 2015 13:56
Show Gist options
  • Save pbalduino/8830747 to your computer and use it in GitHub Desktop.
Save pbalduino/8830747 to your computer and use it in GitHub Desktop.
09. Qual autor tem mais livros publicados?
(ns autores.core
(:require [clojure.pprint :as pp]
[net.cgrand.enlive-html :as en]
[clojure.string :as str])
(:import [java.net URL]))
(defn- get-links [url]
(let [links (-> url
URL.
en/html-resource
(en/select [:body :section :a]))]
(filter
#(. % contains "livro")
(map #(str url ((% :attrs) :href))
links))))
(defn- get-author [url]
(let [authors (-> url
URL.
en/html-resource
(en/select [:span.product-author-link]))]
(str/split
(str/replace
(first
((first authors) :content))
#"(\n| )" "")
#"(, | e )")))
(defn -main [& args]
(println "Os autores com mais publicações na Casa do Código:")
(pp/pprint
(->> "http://www.casadocodigo.com.br"
get-links
(pmap get-author)
flatten
frequencies
(sort-by last >)
(partition-by last)
first))
(shutdown-agents))
@pbalduino
Copy link
Author

Os autores com mais publicações na Casa do Código:
[["Alexandre Saudate" 2]
["Sérgio Lopes" 2]
["Paulo Silveira" 2]
["Tárcio Zemel" 2]
["Anderson Leite" 2]
["Mauricio Aniche" 2]
["Gilliard Cordeiro" 2]
["Hébert Coelho" 2]
["Eduardo Guerra" 2]
["Rafael Steil" 2]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment