PureBytes Links
Trading Reference Links
|
Hello group,
I hope I find someone in the group who can help!
I'm trying to automate daily updates from Yahoo, but still having
problems. I'm trying it for a week now, but don't succeed.
I created a folder C:\Yahoo and copied the URL Get.exe program and
the file Yahoo.js there. But when I doubleclick on the URL Get.exe
to run the program, I retrieve the following message : "You have to
define URL and local file name in program arguments" ! So, where do I
have to do that? And when I doubleclick on Yahoo.js, I retrieve the
following message : URLGET : "The server name or adress could not be
resolved" !
I'm not that good in English (my native language is Dutch) so maybe I
misunderstood the instructions (and yes, I read all newsletters).
It's to difficult for me, so, is there anyone who can explane it,
step by step, using simple terms?
I included the script of the Yahoo.js file so you can check it.
PLEASE, HELP ME !!!
Best regards,
Johan
/*
** AmiBroker/Win32 scripting Example
**
** File: Yahoo.js
** Created: Tomasz Janeczko, March 4rd, 2001
** Purpose: Download and import DAILY updates from Yahoo
** Language: JavaScript (Windows Scripting Host)
**
**
*/
/**************************************************************/
/* Constants */
/**************************************************************/
/* The ticker to check */
/* Set it to empty string "" if you don't want to check */
ChkTicker = "A";
/* The folder where the files will be downloaded */
DestDir = "C:\\Yahoo\\";
/* The name and the path to downloader program */
DownloaderPrg = "URLGet.exe";
/* Force download - if true causes downloading data file */
/* even if it exists on the local drive */
ForceDownloadFlag = true;
/* URL from where data are downloaded */
/* quote.yahoo.com supports US and Canada markets only */
URLPrefix = "http://quote.yahoo.com/d/quotes.csv?s=";
URLPostfix = "&f=snl1d1t1c1ohgv&e=.csv";
/* extension of file name, YYYYMMDD will be prepended */
FileExt = ".aqd";
/* Max. number of tickers to download in one run */
/* Should be no more than 30 because of the limitations of command
line string length */
ChunkSize = 30;
/**************************************************************/
/* Main part */
/**************************************************************/
/* Create AmiBroker app object */
AmiBroker = new ActiveXObject( "Broker.Application" );
/* ... and file system object */
FileSys = new ActiveXObject( "Scripting.FileSystemObject" );
WshShell = new ActiveXObject( "WScript.Shell" );
function Download( URL, filename )
{
if( ! ForceDownloadFlag && FileSys.FileExists( filename ) ) return
true;
if( WshShell.Run( DownloaderPrg + " " + URL + " " + filename, 0,
true ) == 0 ) return true;
WScript.echo("Download of " + URL + " failed." );
return false;
}
function Import( filename )
{
try
{
AmiBroker.Import( 0, filename, "aqd.format" );
}
catch( e )
{
return false;
}
/* refresh ticker list and windows */
AmiBroker.RefreshAll();
return true;
}
function CheckFolder()
{
if( ! FileSys.FolderExists( DestDir ) )
{
FileSys.CreateFolder( DestDir );
}
}
function IsValidDatabase()
{
if( ChkTicker != "" && AmiBroker.Stocks.Count > 0 )
{
try
{
return AmiBroker.Stocks( ChkTicker ).Ticker == ChkTicker;
}
catch( e )
{
WScript.echo("The database currently loaded into AmiBroker does
not have " + ChkTicker + "\nSo I guess this is not correct
database.\nUpdate failed.");
}
}
return false;
}
function Main()
{
bOK = true;
var Today = new Date();
if( ! IsValidDatabase() ) return;
CheckFolder();
var Qty = AmiBroker.Stocks.Count;
var TickerList = "";
var j = 0; /* this variable is used for marking different files from
one day */
for( i = 0; i < Qty; i++ )
{
TickerList += AmiBroker.Stocks( i ).Ticker;
if( ( i % ChunkSize ) == (ChunkSize-1) || i == ( Qty - 1) )
{
y = Today.getFullYear();
m = Today.getMonth() + 1;
d = Today.getDate();
bOK = true;
filename = y + ( m < 10 ? "0" : "" ) + m + ( d < 10 ? "0" : "" ) +
d + "_" + j + FileExt;
URL = URLPrefix + TickerList + URLPostfix;
if( Download( URL, DestDir + filename ) )
{
if( ! Import( DestDir + filename ) ) bOK = false;
}
else
{
bOK = false;
}
if( ! bOK && WshShell.popup( "The download and/or import of the "
+ filename + " has failed.\nThis can be because the data are not
available or network connection problem.\nDo you want to abort?" ,
0, "Abort updating", 4 + 256 ) == 6 )
{
break;
}
j++;
TickerList = "";
}
else
{
TickerList += "+";
}
}
if( bOK ) WScript.echo("Update script finished. Your database is
now up-to-date" );
else WScript.echo("Update script finished. There were,
however, some errors during download/import");
}
Main();
|