http.client: use new http-get* word.

db4
John Benediktsson 2013-10-12 10:25:42 -07:00
parent 18088e1aa3
commit 435f54cf59
18 changed files with 23 additions and 27 deletions

View File

@ -7,7 +7,7 @@ IN: bootstrap.image.download
CONSTANT: url URL" http://downloads.factorcode.org/images/latest/"
: download-checksums ( -- alist )
url "checksums.txt" >url derive-url http-get nip
url "checksums.txt" >url derive-url http-get*
string-lines [ " " split1 ] { } map>assoc ;
: file-checksum ( image -- checksum )

View File

@ -53,9 +53,7 @@ fry http.client kernel urls ;
URL" http://www.oracle.com"
}
2 <semaphore> '[
_ [
http-get nip
] with-semaphore
_ [ http-get* ] with-semaphore
] parallel-map"""
} ;

View File

@ -108,7 +108,7 @@ M: byte-array parse-feed [ bytes>xml xml>feed ] with-html-entities ;
: download-feed ( url -- feed )
#! Retrieve an news syndication file, return as a feed tuple.
http-get nip parse-feed ;
http-get* parse-feed ;
! Atom generation

View File

@ -23,7 +23,7 @@ ERROR: bad-response json status ;
] unless ;
: json-data ( url -- json )
http-get nip json> check-status "data" of ;
http-get* json> check-status "data" of ;
: get-short-url ( short-url path -- data )
<bitly-url> swap "shortUrl" set-query-param json-data ;

View File

@ -22,7 +22,7 @@ title content unescapedUrl url titleNoFormatting fileFormat ;
PRIVATE>
: google-search ( query -- results )
search-url http-get nip json>
search-url http-get* json>
{ "responseData" "results" } deep-at
[ \ search-result from-slots ] map ;

View File

@ -53,7 +53,7 @@ ERROR: response-error response error ;
: translate-tts ( text -- file )
"http://translate.google.com/translate_tts?tl=en" >url
swap "q" set-query-param http-get nip
swap "q" set-query-param http-get*
temporary-file ".mp3" append
[ binary set-file-contents ] keep ;

View File

@ -25,7 +25,7 @@ TUPLE: post title postedBy points id url commentCount postedAgo ;
] map ;
: hacker-news-items ( -- seq )
"http://api.ihackernews.com/page" http-get nip
"http://api.ihackernews.com/page" http-get*
json> "items" of items> ;
: write-title ( title url -- )

View File

@ -6,7 +6,7 @@ sequences sets splitting unicode.case unicode.categories urls
urls.encoding shuffle ;
IN: html.parser.analyzer
: scrape-html ( url -- headers vector )
: scrape-html ( url -- response vector )
http-get parse-html ;
: attribute ( tag string -- obj/f )

View File

@ -21,7 +21,7 @@ SYMBOLS: latest-sources last-built-sources ;
[ maybe-download-image drop ] [ file-checksum ] bi ;
: latest-counter ( -- counter )
counter-url get-global http-get nip string>number ;
counter-url get-global http-get* string>number ;
: update-sources ( -- )
#! Must be run from builds-dir

View File

@ -43,7 +43,7 @@ public_description subscribers title url ;
TUPLE: page url data before after ;
: json-page ( url -- page )
>url dup http-get nip json> "data" of {
>url dup http-get* json> "data" of {
[ "children" of [ parse-data ] map ]
[ "before" of [ f ] when-json-null ]
[ "after" of [ f ] when-json-null ]
@ -54,7 +54,7 @@ TUPLE: page url data before after ;
: get-user-info ( username -- user )
"http://api.reddit.com/user/%s/about" sprintf
http-get nip json> parse-data ;
http-get* json> parse-data ;
: get-url-info ( url -- page )
"http://api.reddit.com/api/info?url=%s" sprintf json-page ;

View File

@ -29,8 +29,8 @@ visit-time request-rate crawl-delay unknowns ;
: >robots.txt-url ( url -- url' )
>url URL" robots.txt" derive-url ;
: get-robots.txt ( url -- headers robots.txt )
>robots.txt-url http-get ;
: get-robots.txt ( url -- robots.txt )
>robots.txt-url http-get* ;
: normalize-robots.txt ( string -- sitemaps seq )
string-lines
@ -98,5 +98,4 @@ PRIVATE>
] map ;
: url>robots ( url -- robots )
>url
dup get-robots.txt nip parse-robots.txt <robots> ;
>url dup get-robots.txt parse-robots.txt <robots> ;

View File

@ -15,7 +15,7 @@ IN: rosetta-code.web-scraping
! and popular such as CPAN for Perl or Boost for C++.
: web-scraping-main ( -- )
"http://tycho.usno.navy.mil/cgi-bin/timer.pl" http-get nip
"http://tycho.usno.navy.mil/cgi-bin/timer.pl" http-get*
[ "UTC" swap start [ 9 - ] [ 1 - ] bi ] keep subseq print ;
MAIN: web-scraping-main

View File

@ -5,8 +5,7 @@ IN: twitter.prettyprint
MEMO: load-http-image ( url -- image/f )
'[ _
[ http-get [ check-response drop ] dip ]
[ image-class ] bi load-image*
[ http-get* ] [ image-class ] bi load-image*
] [ drop f ] recover ;
: user-image ( user -- image/f )

View File

@ -35,7 +35,7 @@ TUPLE: fjsc < dispatcher ;
: do-compile-url ( url -- response )
[
absolute-url http-get nip 'expression' parse fjsc-compile write "();" write
absolute-url http-get* 'expression' parse fjsc-compile write "();" write
] with-string-writer
"application/javascript" <content> ;

View File

@ -40,7 +40,7 @@ IN: wikipedia
"http://en.wikipedia.org/wiki/%s_%s" sprintf ;
: (historical-events) ( timestamp -- seq )
historical-url http-get nip string>xml "ul" deep-tags-named ;
historical-url http-get* string>xml "ul" deep-tags-named ;
: items>sequence ( tag -- seq )
children-tags [ deep-children>string ] map ;
@ -67,7 +67,7 @@ PRIVATE>
: article. ( name -- )
"http://en.wikipedia.org/wiki/%s" sprintf
http-get nip parse-html "content" find-by-id-between
http-get* parse-html "content" find-by-id-between
[ html-text. ] with-string-writer string-lines
[ [ blank? ] trim ] map harvest [
R/ &lt;/ "<" re-replace

View File

@ -16,7 +16,7 @@ SYMBOL: wolfram-api-id
: query ( query -- xml )
url-encode wolfram-api-id get-global
"http://api.wolframalpha.com/v2/query?input=%s&appid=%s"
sprintf http-get nip string>xml
sprintf http-get* string>xml
dup "error" tag-named [
"msg" tag-named children>string throw
] when* ;

View File

@ -11,14 +11,14 @@ IN: xkcd
<PRIVATE
: comic-image ( url -- image )
http-get nip
http-get*
R" http://imgs\.xkcd\.com/comics/[^\.]+\.(png|jpg)"
first-match >string load-http-image ;
: comic-image. ( url -- ) comic-image image. ;
: comic-string ( url -- string )
http-get nip string>xml
http-get* string>xml
"transcript" "id" deep-tag-with-attr children>string ;
: comic-text. ( url -- )

View File

@ -57,4 +57,4 @@ CONSTANT: factor-id "fRrVAKzV34GDyeRw6bUHDhEWHRedwfOC7e61wwXZLgGF80E67spxdQXuugB
swap >>query ;
: yahoo-search ( search -- seq )
query http-get nip string>xml parse-yahoo ;
query http-get* string>xml parse-yahoo ;