Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a46d5b
commit f8c04d6
Showing
3 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,18 @@ | |||
(ns solutions.fight | |||
(:use [clojure.http.client :only (request url-encode)] | |||
[clojure.contrib.json.read :only (read-json)])) | |||
|
|||
(def google-search-base | |||
"http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=") | |||
|
|||
(defn estimated-hits-for | |||
[term] | |||
(let [http-response (request (str google-search-base (url-encode term))) | |||
json-response (read-json (apply str (:body-seq http-response)))] | |||
(Long/parseLong (get-in json-response ["responseData" "cursor" "estimatedResultCount"])))) | |||
|
|||
(defn fight | |||
[term1 term2] | |||
(let [r1 (future (estimated-hits-for term1)) | |||
r2 (future (estimated-hits-for term2))] | |||
(future {term1 @r1 term2 @r2}))) |