Page 1 of 1

Download stock quote file from yahoo

PostPosted: Mon Jun 02, 2008 12:56 am
by thuc18
:( Pls help, want to download quotes.csv file from

:"//finance.yahoo.com/d/quotes.csv?s=BBDB.TO+NT.TO+GE+MSFT&f=snl1d1t1ohgdr"

with thanks
(xharbour/FWH)

PostPosted: Mon Jun 02, 2008 2:39 am
by Rochinha
Try this,

Code: Select all  Expand view
#include "fivewin.ch"

Function Main()

local ws:=TdWebService():new()
? ws:OpenWS("http://finance.yahoo.com/d/quotes.csv?s=BBDB.TO+NT.TO+GE+MSFT&f=snl1d1t1ohgdr")
ws:end()

return nil


TWebsrc.prg
Code: Select all  Expand view
#include "dll.ch"

static xdll
*****************************
CLASS TdWebService
     DATA hOpen
     DATA sbuffer HIDDEN
     DATA xDLL HIDDEN

     METHOD New(buffersize) CONSTRUCTOR

     METHOD OpenWS(url)

     METHOD End()
ENDCLASS
*****************************
METHOD New(conexion,buffersize) CLASS TdWebService
DEFAULT buffersize:=64000
   ::sbuffer:=buffersize
   xDll:=LoadLib32("wininet.dll")
   ::hOpen = InternetOpen("TdWebService", 1,,, 0)
RETURN Self
*****************************
METHOD OpenWS(url) CLASS TdWebService
local hFile,ret,xml
   hFile = InternetOpenUrl(::hOpen, url,"",0,,0)
   xml:=space(::sbuffer)
   InternetReadFile(hFile, @xml, ::sbuffer, @Ret)
return subst(alltrim(xml),1,len(alltrim(xml))-5)
*****************************
METHOD End() CLASS TdWebService
   FreeLib32(xDll)
return nil
*****************************

DLL32 FUNCTION InternetOpen( cApp as LPSTR, n1 AS DWORD, n2 AS LPSTR, n3 AS LPSTR,;
                             n4 AS DWORD ) AS LONG PASCAL ;
                             FROM "InternetOpenA" LIB xdll
Dll32 Function InternetReadFile(hFile As 7, @sBuffer As 8, lNumBytesToRead As 7, @lNumberOfBytesRead As 7) As 7 PASCAL Lib xdll
Dll32 Function InternetOpenUrl(hInternetSession As 7, lpszUrl As 8, lpszHeaders As 8, dwHeadersLength As 7, dwFlags As 7, dwContext As 7) As 7 FROM "InternetOpenUrlA" PASCAL Lib xdll
DLL32 FUNCTION InternetCloseHandle( hSession AS LONG ) AS BOOL PASCAL LIB xdll

PostPosted: Mon Jun 02, 2008 1:15 pm
by thuc18
Thanks Rochinha,
When I complied it produced a lot of error (FWH 7.12/xharbour 1.1.0) such as "parse error at 'hOpen' " , 'sBuffer' etc...

PostPosted: Tue Jun 03, 2008 6:59 pm
by Rochinha
Friend,

Try now:
Code: Select all  Expand view
#include "fivewin.ch"
#include "dll.ch"

static xDLL // Need to TdWebService
static oGet,oSay

Function Main()
   local ws:=TdWebService():new()
   ? ws:OpenWS("http://finance.yahoo.com/d/quotes.csv?s=BBDB.TO+NT.TO+GE+MSFT&f=snl1d1t1ohgdr")
   ws:end()
return nil

CLASS TdWebService
     DATA hOpen
     DATA sbuffer HIDDEN
     DATA xDLL HIDDEN

     METHOD New(buffersize) CONSTRUCTOR

     METHOD OpenWS(url)

     METHOD End()
ENDCLASS

METHOD New(conexion,buffersize) CLASS TdWebService
   DEFAULT buffersize:=64000
   ::sbuffer:=buffersize
   xDll:=LoadLib32("wininet.dll")
   ::hOpen = InternetOpen("TdWebService", 1,,, 0)
   RETURN Self

METHOD OpenWS(url) CLASS TdWebService
   local hFile,ret,xml
   hFile = InternetOpenUrl(::hOpen, url,"",0,,0)
   xml:=space(::sbuffer)
   InternetReadFile(hFile, @xml, ::sbuffer, @Ret)
   return subst(alltrim(xml),1,len(alltrim(xml))-5)

METHOD End() CLASS TdWebService
   FreeLib32(xDll)
   return nil


DLL32 FUNCTION InternetOpen( cApp as LPSTR, n1 AS DWORD, n2 AS LPSTR, n3 AS LPSTR,;
                             n4 AS DWORD ) AS LONG PASCAL ;
                             FROM "InternetOpenA" LIB xdll
Dll32 Function InternetReadFile(hFile As 7, @sBuffer As 8, lNumBytesToRead As 7, @lNumberOfBytesRead As 7) As 7 PASCAL Lib xdll
Dll32 Function InternetOpenUrl(hInternetSession As 7, lpszUrl As 8, lpszHeaders As 8, dwHeadersLength As 7, dwFlags As 7, dwContext As 7) As 7 FROM "InternetOpenUrlA" PASCAL Lib xdll
DLL32 FUNCTION InternetCloseHandle( hSession AS LONG ) AS BOOL PASCAL LIB xdll

PostPosted: Wed Jun 04, 2008 1:34 am
by thuc18
Still get the same error messages. Are we use the same version . I also use FWH 7.12. Thanks again.
xHarbour Compiler build 1.1.0 (SimpLex)
Copyright 1999-2007, http://www.xharbour.org http://www.harbour-project.org/
Compiling 'quote.prg'...
quote.prg(9) Error E0016 Syntax error: '?'
quote.prg(14) Error E0030 Syntax error: "parse error at 'HOPEN'"
quote.prg(15) Error E0030 Syntax error: "parse error at 'SBUFFER'"
quote.p?rg(16) Error E0030 Syntax error: "parse error at 'XDLL'"
quote.prg(18) Error E0030 Syntax error: "parse error at 'NEW'"
quote.prg(20) Error E0030 Syntax error: "parse error at 'OPENWS'"
quote.prg(22) Error E0030 Syntax error: "parse error at 'END'"
quote.prg(23) Error E0030 Syntax error: "parse error at 'TO'"
quote.prg(26) Error E0030 Syntax error: "parse error at 'BUFFERSIZE'"
quote.prg(32) Error E0019 #error: 'Method "OpenWS(url)" not declared in class: TdWebService'
quote.prg(39) Error E0019 #error: 'Method "End()" not declared in class: TdWebService'
quote.prg(46) Error E0030 Syntax error: "parse error at 'FUNCTION'"
12 errors

No code generated

PostPosted: Wed Jun 04, 2008 4:24 am
by James Bott
thuc18,

You should not be getting these errors--they are standard FW commands.

Perhaps your program is not finding the fivewin.ch file? Are you using buildx.bat to compile? Maybe you have an extra line feed somewhere in your code?

James

PostPosted: Wed Jun 04, 2008 5:17 am
by Otto
Rochinha, thank you for the code.
May I put the sample on
http://fwcodesnips.com

Regards,
Otto

PostPosted: Wed Jun 04, 2008 6:25 am
by thuc18
It works now. when I pasted source code from here to Word then convert to text file somehow it had some invisible chr which compiler not like it.
Thank Rochinha for the code and James for hints :D

PostPosted: Wed Jun 04, 2008 8:57 am
by Rochinha
Otto,

Put this code:
Code: Select all  Expand view
#include "fivewin.ch"
#include "dll.ch"

static xDLL // Need to TdWebService
static oGet,oSay

Function Main()
   local oDlg,oFont,WhatQuote:=space(50)
   local cResult := "Samples:" + CRLF + CRLF + "IBM" + CRLF + "MSFT+NO.TO" + CRLF + "DOW+MSFT+IBM"
   DEFINE FONT oFont NAME "ARIAL" SIZE 00,-12 BOLD
   DEFINE DIALOG oDlg TITLE "Push Quotes from Yahoo Finance" FROM 00,00 to 23,80 FONT oFont
          @ 0.6,01 say "Get Quotes: " of oDlg
          @ 0.5,5.5 get oGet var WhatQuote pict "@!" of oDlg
          @ 0.3,43 button "Push" size 44,12 of oDlg ACTION Consulta(WhatQuote)
          @ 02,01 to 12,44 LABEL "Resultado da pesquisa" of oDlg
          @ 2.5,2.2 say oSay var cResult size 290,125 of oDlg color nRGB(255,0,0),getsyscolor(15)
   ACTIVATE DIALOG oDlg CENTERED
   return nil

Function Consulta(WhatQuote)
   local ws:=TdWebService():new()
   cQuotes := ws:OpenWS("http://finance.yahoo.com/d/quotes.csv?s="+WhatQuote+"&f=snl1d1t1ohgdr")
   oSay:settext( cQuotes )
   ws:end()
   return nil

//static xdll
CLASS TdWebService
     DATA hOpen
     DATA sbuffer HIDDEN
     DATA xDLL HIDDEN

     METHOD New(buffersize) CONSTRUCTOR

     METHOD OpenWS(url)

     METHOD End()
ENDCLASS

METHOD New(conexion,buffersize) CLASS TdWebService
   DEFAULT buffersize:=64000
   ::sbuffer:=buffersize
   xDll:=LoadLib32("wininet.dll")
   ::hOpen = InternetOpen("TdWebService", 1,,, 0)
   RETURN Self

METHOD OpenWS(url) CLASS TdWebService
   local hFile,ret,xml
   hFile = InternetOpenUrl(::hOpen, url,"",0,,0)
   xml:=space(::sbuffer)
   InternetReadFile(hFile, @xml, ::sbuffer, @Ret)
   return subst(alltrim(xml),1,len(alltrim(xml))-5)

METHOD End() CLASS TdWebService
   FreeLib32(xDll)
   return nil

DLL32 FUNCTION InternetOpen( cApp as LPSTR, n1 AS DWORD, n2 AS LPSTR, n3 AS LPSTR,;
                             n4 AS DWORD ) AS LONG PASCAL ;
                             FROM "InternetOpenA" LIB xdll
Dll32 Function InternetReadFile(hFile As 7, @sBuffer As 8, lNumBytesToRead As 7, @lNumberOfBytesRead As 7) As 7 PASCAL Lib xdll
Dll32 Function InternetOpenUrl(hInternetSession As 7, lpszUrl As 8, lpszHeaders As 8, dwHeadersLength As 7, dwFlags As 7, dwContext As 7) As 7 FROM "InternetOpenUrlA" PASCAL Lib xdll
DLL32 FUNCTION InternetCloseHandle( hSession AS LONG ) AS BOOL PASCAL LIB xdll


Note: The credits for de TWebService Class is not for me.