Page 1 of 1

Read_CSV_Data_from_Website Please help

Posted: Sun Jun 11, 2006 11:24 pm
by yrret
I tried the program 'Read_CSV_Data_from_Website.pb' listed in the CodeArchiv data base, and can't seem to get it to work. I used the convert 3.94 to 4.0 , and added some Debug commands to it as listed in the listed source, as well as some command info from the help file.
InitNetwork() does = 1, but ConnectionID always = 0. I also tried different addresses. The help file lists those commands and would seem to indicate that it should work. Could some one please tell me what's wrong or why it dosen't work. What I am looking for, is just what the program seems it should be able to do. And that is to download stock data. I'm writing a stock chart program, and need a good way to interface with an internet site to download the entered stocks data. Thanks for any help and suggestions. Or if there may be a better way of doing it, I would really appreciate your help and suggestions.

Code: Select all

; Converted by PBSourceConverter on 11.06.2006 / 16:42
; English forum: http://purebasic.myforums.net/viewtopic.php?t=6642&highlight=
; Author: ricardo
; Date: 20. June 2003

result=InitNetwork()
;This command must be called before any other command from the Network library. 
;If the 'Result is 0, there is no TCP/IP stack available on the system
Debug "InitNetwork() = " +Str(result)

ConnectionID = OpenNetworkConnection("table.finance.yahoo.com", 80) 
;Connection = OpenNetworkConnection(ServerName$, Port [, Mode]) 
;'ServerName$' can be an IP address or a full name (ie: "127.0.0.1" or "ftp.home.net"). 
Debug "ConnectionID = " +Str(ConnectionID)

If ConnectionID 
  com$="GET http://table.finance.yahoo.com/table.csv?s=IBM&g=d HTTP/1.1"+Chr(13)+Chr(10) 
  com$=com$+"Accept: */*"+Chr(13)+Chr(10) 
  com$=com$+"Accept: text/html"+Chr(13)+Chr(10) 
  com$=com$+"Host: "+host$+Chr(13)+Chr(10) 
  com$=com$+"User-Agent: Yahoo CVS Parser"+Chr(13)+Chr(10) 
  com$=com$+Chr(13)+Chr(10) 
  Res = SendNetworkData(ConnectionID,@com$,Len(com$)) 

    Repeat 
    Delay(10) 
    Result = NetworkClientEvent(ConnectionID) 
    Debug "NetworkClientEvent(ConnectionID) = " +Str(Result)
    
    Select Result 
  
    Case 2 
      Content$ = Space(14500) 
      ReceiveNetworkData(ConnectionID,@Content$,14500) 
      Ok = 1 
      MessageRequester("Done!","Your Data" + Chr(13) + Chr(10) + Content$,0) 
      CloseNetworkConnection(ConnectionID) 
    EndSelect 
    
    Until Ok = 1 
EndIf 

; ExecutableFormat=Windows
; FirstLine=1
; EOF

Posted: Mon Jun 12, 2006 3:07 pm
by Mark1Up
It looks like Yahoo has changed the URLs used for getting the stock data in CSV format. Update the following 2 lines as shown below and it works again. You may need to try pulling up a few historical data samples to figure out what all the parameters are for the URL.

Regards,
Mark

Code: Select all

ConnectionID = OpenNetworkConnection("ichart.finance.yahoo.com", 80)

com$="GET http://ichart.finance.yahoo.com/table.csv?s=IBM&a=00&b=2&c=2005&d=05&e=12&f=2006&g=d&ignore=.csv HTTP/1.1"+Chr(13)+Chr(10)

Posted: Mon Jun 12, 2006 3:20 pm
by Edwin Knoppert
URLDownloadToFile_() ?


Just tested:

URLDownloadToFile_( 0, "http://ichart.finance.yahoo.com/table.c ... gnore=.csv", "c:\hello.csv", 0, 0 )

Posted: Mon Jun 12, 2006 11:24 pm
by yrret
Thanks Mark1Up and Edwin Knopper for you replies.

I updated the 2 lines as you suggested but it still gave a 0 and wouldn't work. Then I did the following:
cn$="ichart.finance.yahoo.com"
ConnectionID = OpenNetworkConnection(cn$, 80)

and it worked!

Then I put it back your way again just to retry and it still worked.
I have no idea why it didn't work the first time?
All I did was copy and paste.

Is there any other source of information on these commands that you know of or can point me to so that I
may get a better understanding of how to use them? The help file provides basic information, and a search
on the forum gets more confusing because most of the found stuff refers to earlier versions of PureBasic
which are different now.

Thanks for any aditional help.

Posted: Tue Jun 13, 2006 2:17 am
by Mark1Up
I'm glad to hear that you got it working. I would be interested to see what you come up with for a stock charting program (I've been thinking about taking a stab at a stock analysis program myself).

The Network commands are documented in the PureBasic help file. The actual HTML commands should be pretty standard but I don't really know HTML that well so I can't be of much help there.

Regards,
Mark