2008-06-01 02:23:11 -04:00
|
|
|
! Copyright (C) 2006 Daniel Ehrenberg, Walton Chan
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
USING: http.client xml xml.utilities kernel sequences
|
2008-06-02 18:51:06 -04:00
|
|
|
namespaces http math.parser help math.order locals
|
|
|
|
urls accessors ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: yahoo
|
|
|
|
|
|
|
|
TUPLE: result title url summary ;
|
|
|
|
|
|
|
|
C: <result> result
|
2008-06-01 02:23:11 -04:00
|
|
|
|
|
|
|
TUPLE: search query results adult-ok start appid region type
|
|
|
|
format similar-ok language country site subscription license ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: parse-yahoo ( xml -- seq )
|
2007-12-23 14:57:39 -05:00
|
|
|
"Result" deep-tags-named [
|
2007-09-20 18:09:08 -04:00
|
|
|
{ "Title" "Url" "Summary" }
|
2008-01-09 17:36:30 -05:00
|
|
|
[ tag-named children>string ] with map
|
2007-09-20 18:09:08 -04:00
|
|
|
first3 <result>
|
|
|
|
] map ;
|
|
|
|
|
|
|
|
: yahoo-url ( -- str )
|
2008-05-24 13:17:08 -04:00
|
|
|
"http://search.yahooapis.com/WebSearchService/V1/webSearch" ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-06-01 02:23:11 -04:00
|
|
|
: param ( search str quot -- search )
|
|
|
|
>r over r> call [ url-encode [ % ] bi@ ] [ drop ] if* ;
|
|
|
|
inline
|
|
|
|
|
|
|
|
: num-param ( search str quot -- search )
|
|
|
|
[ dup [ number>string ] when ] compose param ; inline
|
|
|
|
|
|
|
|
: bool-param ( search str quot -- search )
|
|
|
|
[ "1" and ] compose param ; inline
|
|
|
|
|
|
|
|
: query ( search -- url )
|
2007-09-20 18:09:08 -04:00
|
|
|
[
|
2008-06-01 02:23:11 -04:00
|
|
|
yahoo-url %
|
|
|
|
"?appid=" [ appid>> ] param
|
|
|
|
"&query=" [ query>> ] param
|
|
|
|
"®ion=" [ region>> ] param
|
|
|
|
"&type=" [ type>> ] param
|
|
|
|
"&format=" [ format>> ] param
|
|
|
|
"&language=" [ language>> ] param
|
|
|
|
"&country=" [ country>> ] param
|
|
|
|
"&site=" [ site>> ] param
|
|
|
|
"&subscription=" [ subscription>> ] param
|
|
|
|
"&license=" [ license>> ] param
|
|
|
|
"&results=" [ results>> ] num-param
|
|
|
|
"&start=" [ start>> ] num-param
|
|
|
|
"&adult_ok=" [ adult-ok>> ] bool-param
|
|
|
|
"&similar_ok=" [ similar-ok>> ] bool-param
|
|
|
|
drop
|
2007-09-20 18:09:08 -04:00
|
|
|
] "" make ;
|
|
|
|
|
2008-05-24 13:17:08 -04:00
|
|
|
: factor-id
|
|
|
|
"fRrVAKzV34GDyeRw6bUHDhEWHRedwfOC7e61wwXZLgGF80E67spxdQXuugBe2pgIevMmKwA-" ;
|
|
|
|
|
2008-06-01 02:23:11 -04:00
|
|
|
: <search> ( query -- search )
|
|
|
|
search new
|
|
|
|
factor-id >>appid
|
|
|
|
10 >>results
|
|
|
|
swap >>query ;
|
2008-05-24 13:17:08 -04:00
|
|
|
|
2008-06-01 02:23:11 -04:00
|
|
|
: search-yahoo ( search -- seq )
|
|
|
|
query http-get string>xml parse-yahoo ;
|