Skip to content

Commit

Permalink
Implémenté multi-méthode 'ingest' pour script ImmoStreet (+ refact. n…
Browse files Browse the repository at this point in the history
…oms des méthodes)
  • Loading branch information
olange committed Jul 1, 2013
1 parent efa1eab commit 90f171a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/flat_hunter/ingest/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[flat-hunter.ingest.interface :as interface]))

(def providers
[ :brolliet ])
[ :brolliet :immostreet ])

(defn ingest-all
[]
Expand Down
4 changes: 3 additions & 1 deletion src/flat_hunter/ingest/interface.clj
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(ns flat-hunter.ingest.interface)

(defmulti ingest identity)
(defmulti ingest
"Return all flats details"
identity)
21 changes: 10 additions & 11 deletions src/flat_hunter/ingest/is.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
(ns flat-hunter.ingest.is
(:require [hickory.core :as h]
[hickory.select :as s]))
[hickory.select :as s]
[flat-hunter.ingest.interface :as interface]))


(def immostreet-results-url-pattern
"http://www.immostreet.ch/fr/AdZone/Lookup/d1a01cea-17f5-41b4-94cf-1040a857b48e/%d/MonthlyRent_ASC?resultPerPage=%d")
"http://www.immostreet.ch/fr/AdZone/Lookup/7e4443e1-50fa-4fe1-a233-407f05fb6bbe/%d/MonthlyRent_ASC?resultPerPage=%d")

(defn result-pages
"Returns the list of URIs to scrape"
Expand Down Expand Up @@ -35,8 +36,8 @@
(map #(str "http://www.immostreet.ch" %) links)
))

(defn all-links-to-flats []
(flatten (map links-to-flats (result-pages 21 50))))
(defn flat-urls []
(flatten (map links-to-flats (result-pages 21 1))))

(defn make-field
[flat-elt]
Expand Down Expand Up @@ -79,13 +80,11 @@
)
)

(defn flats
"Return all flats details"
[]
(time
(doseq [ flat-page (all-links-to-flats) ]
(println (fetch-flat-details flat-page)) (flush)
)))
(defmethod interface/ingest :immostreet
[provider-name]
(for [url (flat-urls)]
(fetch-flat-details url)
))

;; TODO: Read the details of each ad contained in 'is-results' and create a vector of result maps

Expand Down

0 comments on commit 90f171a

Please sign in to comment.