Last active
August 29, 2015 13:56
-
-
Save pbalduino/8830747 to your computer and use it in GitHub Desktop.
09. Qual autor tem mais livros publicados?
This file contains 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 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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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]]