factor/extra/yahoo/yahoo.factor

32 lines
800 B
Factor
Raw Normal View History

2007-09-20 18:09:08 -04:00
! Copyright (C) 2006 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license.
USING: http.client xml xml.utilities kernel sequences
namespaces http math.parser help ;
IN: yahoo
TUPLE: result title url summary ;
C: <result> result
: 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" }
[ tag-named children>string ] curry* map
first3 <result>
] map ;
: yahoo-url ( -- str )
"http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=Factor-search&query=" ;
: query ( search num -- url )
[
yahoo-url %
swap url-encode %
"&results=" % #
] "" make ;
: search-yahoo ( search num -- seq )
query http-get 2nip
[ "Search failed" throw ] unless*
string>xml parse-yahoo ;