From 3c16ee05b7f96aa5496ed275e65822123b90533d Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Tue, 24 Jul 2012 11:57:42 -0700 Subject: [PATCH] google.search: adding simple wrapper for Google Search API. --- extra/google/search/authors.txt | 1 + extra/google/search/search.factor | 67 ++++++++++++++++++++++++++++++ extra/google/search/summary.txt | 1 + extra/google/translate/summary.txt | 1 + 4 files changed, 70 insertions(+) create mode 100644 extra/google/search/authors.txt create mode 100644 extra/google/search/search.factor create mode 100644 extra/google/search/summary.txt create mode 100644 extra/google/translate/summary.txt diff --git a/extra/google/search/authors.txt b/extra/google/search/authors.txt new file mode 100644 index 0000000000..e091bb8164 --- /dev/null +++ b/extra/google/search/authors.txt @@ -0,0 +1 @@ +John Benediktsson diff --git a/extra/google/search/search.factor b/extra/google/search/search.factor new file mode 100644 index 0000000000..0120459375 --- /dev/null +++ b/extra/google/search/search.factor @@ -0,0 +1,67 @@ +! Copyright (C) 2011 John Benediktsson +! See http://factorcode.org/license.txt for BSD license + +USING: accessors arrays assocs assocs.extras classes.tuple +colors.constants combinators formatting fry http.client io +io.styles json.reader kernel sequences urls wrap.strings ; + +IN: google.search + + + +: http-search ( query -- results ) + search-url http-get nip json> + { "responseData" "results" } deep-at + [ \ search-result from-slots ] map ; + +url H{ + { font-name "monospace" } + { foreground COLOR: dark-green } + } [ write-object ] with-style nl ; + +PRIVATE> + +: http-search. ( query -- ) + [ "Search results for '%s'" sprintf write-heading nl ] + [ http-search ] bi [ + { + [ titleNoFormatting>> write-title ] + [ content>> write-content ] + [ unescapedUrl>> write-url ] + } cleave nl + ] each ; diff --git a/extra/google/search/summary.txt b/extra/google/search/summary.txt new file mode 100644 index 0000000000..8ceb1a5f0f --- /dev/null +++ b/extra/google/search/summary.txt @@ -0,0 +1 @@ +Google Search API diff --git a/extra/google/translate/summary.txt b/extra/google/translate/summary.txt new file mode 100644 index 0000000000..1ad2e5f62b --- /dev/null +++ b/extra/google/translate/summary.txt @@ -0,0 +1 @@ +Google Translate API