From: dbh
Subject: Trivial HTTP & Streams
Date: 
Message-ID: <871wvzbn6s.fsf@david.hodge.id.au>
Hi all,

yes - a newbie kind of question.

I want to get some stock prices from a web page.

So I am using thhtp:http-get to get the web page, which I want to then
parse

However, I have struck a slight obstacle, which is more about my level
of knowledge I guess.

THTTP:HTTP-GET returns a list , the last element of which, in SBCL at
least, appears to be a stream SB-SYS:FD-STREAM. When I try to do
something like the following:

(defun character-stream-to-string (input-stream) "Convert stream to
string. For using with trivial-http responses."  
  (let ((strlist nil))
     (do ((line (read-line input-stream nil nil)
	  (read-line input-stream nil nil)))
         ((null line) (apply #'concatenate 'string (reverse strlist))) 
   (push line strlist))))


(defun get-portfolio (portfolio-url) 
  (let ((html-stream (last (thttp:http-get portfolio-url))))
     (character-stream-to-string html-stream)))

I invariably get a "no applicable method" when ever I attempt to read
the stream.  Does'nt matter if I use a read-line, read-sequence or a
read-char or read .

Therefore, I must be missing something blindingly obvious. Google
(usually my friend here), shows me other people just using read-line
(thats where I got the first character-stream-to-string function BTW).

Happy to be pointed in the right direction

Many thanks!

From: Pascal Bourguignon
Subject: Re: Trivial HTTP & Streams
Date: 
Message-ID: <87psjjjyrw.fsf@thalassa.informatimago.com>
dbh <ยทยทยท@david.hodge.id.au> writes:
> [...]
> (defun get-portfolio (portfolio-url) 
>   (let ((html-stream (last (thttp:http-get portfolio-url))))
>      (character-stream-to-string html-stream)))
>
> I invariably get a "no applicable method" when ever I attempt to read
> the stream.  Does'nt matter if I use a read-line, read-sequence or a
> read-char or read . 
> [...]

Look carefully the error message!
Here is for another example, what I get with clisp:

[63]> (asdf-load :trivial-http)
0 errors, 0 warnings
NIL
[64]> (defun character-stream-to-string (input-stream) "Convert stream to
string. For using with trivial-http responses."  
  (let ((strlist nil))
     (do ((line (read-line input-stream nil nil)
	  (read-line input-stream nil nil)))
         ((null line) (apply #'concatenate 'string (reverse strlist))) 
   (push line strlist))))
CHARACTER-STREAM-TO-STRING
[65]> (defun get-portfolio (portfolio-url) 
  (let ((html-stream (last (thttp:http-get portfolio-url))))
     (character-stream-to-string html-stream)))
GET-PORTFOLIO
[66]> (get-portfolio "http://www.informatimago.com/cv-short-en.html")

*** - READ-LINE: argument
       (#<IO UNBUFFERED SOCKET-STREAM CHARACTER www.informatimago.com:80>)
      is not a stream
The following restarts are available:
USE-VALUE      :R1      You may input a value to be used instead.
ABORT          :R2      ABORT
Break 1 [67]> 







The error is in get-portfolio.  









Read again CLHS last:
http://www.lispworks.com/reference/HyperSpec/Body/f_last.htm


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

HEALTH WARNING: Care should be taken when lifting this product,
since its mass, and thus its weight, is dependent on its velocity
relative to the user.
From: Alan Manuel K. Gloria
Subject: Re: Trivial HTTP & Streams
Date: 
Message-ID: <1145074446.344170.182570@z34g2000cwc.googlegroups.com>
Hint 1: It's not a stream.  It's a stream in a.....










Hint 2: parentheses:
*** - READ-LINE: argument
       (#<IO UNBUFFERED SOCKET-STREAM CHARACTER
www.informatimago.com:80>)
      is not a stream











hint 3: check out the function 'last :
http://www.lisp.org/HyperSpec/Body/fun_last.html