Yahoo updates
parent
753edf7c4c
commit
b88a383151
|
@ -1 +1,2 @@
|
||||||
Daniel Ehrenberg
|
Daniel Ehrenberg
|
||||||
|
Walton Chan
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Yahoo! search example using XML-RPC
|
Yahoo! search example using XML
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
USING: tools.test yahoo kernel io.files xml sequences ;
|
USING: tools.test yahoo kernel io.files xml sequences accessors ;
|
||||||
|
|
||||||
[ T{
|
[ T{
|
||||||
result
|
result
|
||||||
|
@ -8,4 +8,4 @@ USING: tools.test yahoo kernel io.files xml sequences ;
|
||||||
"Official site with news, tour dates, discography, store, community, and more."
|
"Official site with news, tour dates, discography, store, community, and more."
|
||||||
} ] [ "resource:extra/yahoo/test-results.xml" file>xml parse-yahoo first ] unit-test
|
} ] [ "resource:extra/yahoo/test-results.xml" file>xml parse-yahoo first ] unit-test
|
||||||
|
|
||||||
[ "http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=Factor-search&query=hi&results=1" ] [ "hi" 1 "Factor-search" query ] unit-test
|
[ "http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=Factor-search&query=hi&results=2&similar_ok=1" ] [ "hi" <search> "Factor-search" >>appid 2 >>results t >>similar-ok query ] unit-test
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
! Copyright (C) 2006 Daniel Ehrenberg
|
! Copyright (C) 2006 Daniel Ehrenberg, Walton Chan
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: http.client xml xml.utilities kernel sequences
|
USING: http.client xml xml.utilities kernel sequences
|
||||||
namespaces http math.parser help math.order locals ;
|
namespaces http math.parser help math.order locals accessors ;
|
||||||
IN: yahoo
|
IN: yahoo
|
||||||
|
|
||||||
TUPLE: result title url summary ;
|
TUPLE: result title url summary ;
|
||||||
|
|
||||||
C: <result> result
|
C: <result> result
|
||||||
|
|
||||||
|
TUPLE: search query results adult-ok start appid region type
|
||||||
|
format similar-ok language country site subscription license ;
|
||||||
|
|
||||||
: parse-yahoo ( xml -- seq )
|
: parse-yahoo ( xml -- seq )
|
||||||
"Result" deep-tags-named [
|
"Result" deep-tags-named [
|
||||||
{ "Title" "Url" "Summary" }
|
{ "Title" "Url" "Summary" }
|
||||||
|
@ -18,19 +21,44 @@ C: <result> result
|
||||||
: yahoo-url ( -- str )
|
: yahoo-url ( -- str )
|
||||||
"http://search.yahooapis.com/WebSearchService/V1/webSearch" ;
|
"http://search.yahooapis.com/WebSearchService/V1/webSearch" ;
|
||||||
|
|
||||||
:: query ( search num appid -- url )
|
: 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 )
|
||||||
[
|
[
|
||||||
yahoo-url %
|
yahoo-url %
|
||||||
"?appid=" % appid %
|
"?appid=" [ appid>> ] param
|
||||||
"&query=" % search url-encode %
|
"&query=" [ query>> ] param
|
||||||
"&results=" % num #
|
"®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
|
||||||
] "" make ;
|
] "" make ;
|
||||||
|
|
||||||
: factor-id
|
: factor-id
|
||||||
"fRrVAKzV34GDyeRw6bUHDhEWHRedwfOC7e61wwXZLgGF80E67spxdQXuugBe2pgIevMmKwA-" ;
|
"fRrVAKzV34GDyeRw6bUHDhEWHRedwfOC7e61wwXZLgGF80E67spxdQXuugBe2pgIevMmKwA-" ;
|
||||||
|
|
||||||
: search-yahoo/id ( search num id -- seq )
|
: <search> ( query -- search )
|
||||||
query http-get string>xml parse-yahoo ;
|
search new
|
||||||
|
factor-id >>appid
|
||||||
|
10 >>results
|
||||||
|
swap >>query ;
|
||||||
|
|
||||||
: search-yahoo ( search num -- seq )
|
: search-yahoo ( search -- seq )
|
||||||
factor-id search-yahoo/id ;
|
query http-get string>xml parse-yahoo ;
|
||||||
|
|
Loading…
Reference in New Issue