Files
Work/http/SCRAPS.TXT
2024-08-07 09:16:27 -04:00

453 lines
12 KiB
Plaintext

//#include <http/table.hpp>
//#include <http/scan.hpp>
//#include <http/reader.hpp>
// Table symbolTable;
// FileHandle srcFile("c:\\work\\http\\htm\\csis.htm",FileHandle::Read,FileHandle::ShareRead);
// FileMap srcMap(srcFile);
// FileMap dstMap("OUTMAP",0,250000,FileMap::ReadWrite,FileMap::Commit);
// PureViewOfFile srcView(srcMap);
// PureViewOfFile dstView(dstMap);
// Scan htmlScan(srcView,dstView,symbolTable);
// htmlScan.analyze();
// FundReader fundReader;
// fundReader.readQuote("c:\\work\\http\\htm\\csis.htm","");
#include <common/filemap.hpp>
#include <common/pview.hpp>
void parseData(void)
{
FileHandle readFile("C:\\WORK\\HTTP\\DATA.DAT",FileHandle::Read);
FileHandle writeFile("C:\\WORK\\HTTP\\DATA.TXT",FileHandle::Write,FileHandle::ShareNone,FileHandle::Overwrite);
FileMap readMap(readFile);
PureViewOfFile readView(readMap);
String inLine;
String security;
String ticker;
String prefix;
int tickPos;
int count(18);
while(readView.getLine(inLine))
{
::sprintf(prefix,"N%d=",count++);
security=inLine.betweenString('=','<');
if(security.isNull())continue;
tickPos=inLine.strpos("TICKER=");
if(-1==tickPos)continue;
ticker=inLine.substr(tickPos);
if(ticker.isNull())continue;
ticker=ticker.betweenString('=','"');
if(ticker.isNull())continue;
prefix+=security;
prefix+=";";
prefix+=ticker;
writeFile.writeLine(prefix);
}
void parseData(void)
{
FileHandle readFile("C:\\WORK\\HTTP\\DATA.DAT",FileHandle::Read);
FileHandle writeFile("C:\\WORK\\HTTP\\DATA.TXT",FileHandle::Write,FileHandle::ShareNone,FileHandle::Overwrite);
FileMap readMap(readFile);
PureViewOfFile readView(readMap);
String inLine;
String prefix;
String security;
String ticker;
char *lpThumb;
char *lpCursor;
int count(1);
while(readView.getLine(inLine))
{
::sprintf(prefix,"N%d=",count++);
lpThumb=lpCursor=((char*)inLine)+40;
while(*lpCursor==' ')lpCursor--;
*(lpCursor+1)=0;
security=inLine;
lpCursor=++lpThumb;
while(*lpCursor!=' ')lpCursor++;
*lpCursor=0;
ticker=lpThumb;
prefix+=security;
prefix+=";";
prefix+=ticker;
writeFile.writeLine(prefix);
}
}
void Scan::analyze(void)
{
readch();
while((int)mChar!=-1&&mChar!=0x001A)
{
skipSeparators();
if(0xFFFF==mChar||0x001A==mChar)break;
if(isdigit(mChar))scanNumeral();
else if(isalpha(mChar))scanWord();
else if(mChar=='\r')scanNewLine();
else if(mChar=='"')scanLiteral();
else if(mChar=='<')scanLeftAngle();
else if(mChar=='>')scanRightAngle();
else if(mChar=='/')scanForwardSlash();
else if(mChar=='&')scanAmpersand();
else scanUnknown();
// else scanWord();
}
emit(endtext1);
}
class StockReader : private Reader
{
public:
StockReader(void);
virtual ~StockReader();
WORD readQuote(const String &pathFileName,StockQuote &someStockQuote);
private:
enum Key{Description,Symbol,Last,Change,Volume,Open,Bid,Low,Low52,End};
void handleDescriptionKey(const String &quoteLine,StockQuote &someStockQuote);
void handleSymbolKey(const String &quoteLine,StockQuote &someStockQuote);
void handleLastKey(const String &quoteLine,StockQuote &someStockQuote);
void handleChangeKey(const String &quoteLine,StockQuote &someStockQuote);
void handleVolumeKey(const String &quoteLine,StockQuote &someStockQuote);
void handleOpenKey(const String &quoteLine,StockQuote &someStockQuote);
void handleBidKey(const String &quoteLine,StockQuote &someStockQuote);
void handleLowKey(const String &quoteLine,StockQuote &someStockQuote);
void handleLowKey52(const String &quoteLine,StockQuote &someStockQuote);
String mDescriptionKey;
String mLastKey;
String mChangeKey;
String mVolumeKey;
String mOpenKey;
String mBidKey;
String mLowKey;
String mLowKey52;
};
StockReader::StockReader(void)
: mDescriptionKey("<td width=330 align=center><strong>"),
mLastKey("glossary.html#last"),
mChangeKey("glossary.html#change"),
mVolumeKey("glossary.html#volume"),
mOpenKey("glossary.html#open"),
mBidKey("glossary.html#bid"),
mLowKey("glossary.html#low"),
mLowKey52("glossary.html#52low")
{
}
inline
StockReader::~StockReader()
{
}
WORD StockReader::readQuote(const String &pathFileName,StockQuote &someStockQuote)
{
FileHandle quoteFile(pathFileName);
if(!quoteFile.isOkay())return FALSE;
FileMap quoteMap(quoteFile);
PureViewOfFile quoteView(quoteMap);
Key expectKey;
String quoteLine;
expectKey=Description;
while(TRUE)
{
if(End==expectKey||!quoteView.getLine(quoteLine))break;
switch(expectKey)
{
case Description :
if(!quoteLine.strstr(mDescriptionKey))break;
handleDescriptionKey(quoteLine,someStockQuote);
expectKey=Symbol;
break;
case Symbol :
handleSymbolKey(quoteLine,someStockQuote);
expectKey=Last;
break;
case Last :
if(!quoteLine.strstr(mLastKey))break;
handleLastKey(quoteLine,someStockQuote);
expectKey=Change;
break;
case Change :
if(!quoteLine.strstr(mChangeKey))break;
handleChangeKey(quoteLine,someStockQuote);
expectKey=Volume;
break;
case Volume :
if(!quoteLine.strstr(mVolumeKey))break;
handleVolumeKey(quoteLine,someStockQuote);
expectKey=Open;
break;
case Open :
if(!quoteLine.strstr(mOpenKey))break;
handleOpenKey(quoteLine,someStockQuote);
expectKey=Bid;
break;
case Bid :
if(!quoteLine.strstr(mBidKey))break;
handleBidKey(quoteLine,someStockQuote);
expectKey=Low;
break;
case Low :
if(!quoteLine.strstr(mLowKey))break;
handleLowKey(quoteLine,someStockQuote);
expectKey=Low52;
break;
case Low52 :
if(!quoteLine.strstr(mLowKey52))break;
handleLowKey52(quoteLine,someStockQuote);
expectKey=End;
break;
}
}
}
void StockReader::handleDescriptionKey(const String &quoteLine,StockQuote &someStockQuote)
{
char *pString;
String descriptionString;
pString=(LPSTR)quoteLine+quoteLine.length();
while(*(pString)!='>')pString--;
descriptionString=++pString;
descriptionString.trimRight();
someStockQuote.description(descriptionString);
winConsole.writeLine(String("Description:")+descriptionString);
}
void StockReader::handleSymbolKey(const String &quoteLine,StockQuote &someStockQuote)
{
String symbolString(quoteLine.betweenString('(',')'));
someStockQuote.symbol(symbolString);
winConsole.writeLine(String("Symbol:")+symbolString);
}
void StockReader::handleLastKey(const String &quoteLine,StockQuote &someStockQuote)
{
String lastTraded;
String dateTime;
getAt(7,String(quoteLine),lastTraded);
getAt(14,String(quoteLine),dateTime);
winConsole.writeLine(String("Last Traded:")+lastTraded);
winConsole.writeLine(String("DateTime:")+dateTime);
someStockQuote.lastTraded(strToDec(lastTraded));
}
void StockReader::handleChangeKey(const String &quoteLine,StockQuote &someStockQuote)
{
String changeInValueDollars;
String changeInValuePercent;
if(!getAt(7,String(quoteLine),changeInValueDollars))
{
getAt(8,String(quoteLine),changeInValueDollars);
if(!getAt(17,String(quoteLine),changeInValuePercent))
getAt(19,String(quoteLine),changeInValuePercent);
}
else
{
if(!getAt(16,String(quoteLine),changeInValuePercent))
getAt(14,String(quoteLine),changeInValuePercent);
}
winConsole.writeLine(String("$ Change:")+changeInValueDollars);
winConsole.writeLine(String("% Change:")+changeInValuePercent);
someStockQuote.dollarChange(strToDec(changeInValueDollars));
someStockQuote.percentChange(::atof(changeInValuePercent));
}
void StockReader::handleVolumeKey(const String &quoteLine,StockQuote &someStockQuote)
{
String volume;
String trades;
if(!getAt(6,String(quoteLine),volume))getAt(8,String(quoteLine),volume);
getAt(12,String(quoteLine),trades);
winConsole.writeLine(String("Volume:")+volume);
winConsole.writeLine(String("Trades:")+trades);
someStockQuote.volume(::atoi(volume));
someStockQuote.trades(::atoi(trades));
}
void StockReader::handleOpenKey(const String &quoteLine,StockQuote &someStockQuote)
{
String open;
String previousClose;
getAt(6,String(quoteLine),open);
getAt(12,String(quoteLine),previousClose);
winConsole.writeLine(String("Open:")+open);
winConsole.writeLine(String("Previous Close:")+previousClose);
someStockQuote.openingPrice(strToDec(open));
someStockQuote.previousClose(strToDec(previousClose));
}
void StockReader::handleBidKey(const String &quoteLine,StockQuote &someStockQuote)
{
String bid;
String ask;
getAt(6,String(quoteLine),bid);
getAt(12,String(quoteLine),ask);
winConsole.writeLine(String("Bid:")+bid);
winConsole.writeLine(String("Ask:")+ask);
someStockQuote.bid(strToDec(bid));
someStockQuote.ask(strToDec(ask));
}
void StockReader::handleLowKey(const String &quoteLine,StockQuote &someStockQuote)
{
String dayLow;
String dayHigh;
getAt(6,String(quoteLine),dayLow);
getAt(12,String(quoteLine),dayHigh);
winConsole.writeLine(String("Day Low:")+dayLow);
winConsole.writeLine(String("Day High:")+dayHigh);
someStockQuote.dayLow(strToDec(dayLow));
someStockQuote.dayHigh(strToDec(dayHigh));
}
void StockReader::handleLowKey52(const String &quoteLine,StockQuote &someStockQuote)
{
String weekLow52;
String weekHigh52;
getAt(6,String(quoteLine),weekLow52);
getAt(12,String(quoteLine),weekHigh52);
winConsole.writeLine(String("52 Week Low:")+weekLow52);
winConsole.writeLine(String("52 Week High:")+weekHigh52);
someStockQuote.low52(strToDec(weekLow52));
someStockQuote.high52(strToDec(weekHigh52));
}
// **************************************************************************
#include <common/finddata.hpp>
#include <common/openfile.hpp>
#include <common/pview.hpp>
#include <common/filemap.hpp>
#include <http/stock.hpp>
#include <http/reader.hpp>
#include <common/openfile.hpp>
#include <common/filemap.hpp>
#include <common/pview.hpp>
#if 0
int PASCAL WinMain(HINSTANCE /*hInstance*/,HINSTANCE /*hPrevInstance*/,LPSTR /*lpszCmdLine*/,int /*nCmdShow*/)
{
String strLine;
String strDescription;
String strSymbol;
String sqlString;
FileHandle inFile("mutual.txt",FileHandle::Read,FileHandle::ShareRead);
FileMap inMap(inFile);
PureViewOfFile inView(inMap);
SQLDb sqlDb;
SQLStatement sqlStatement;
sqlDb.open("Exchange","dba","sql");
if(!sqlDb.isOkay())return FALSE;
sqlStatement=sqlDb;
while(inView.getLine(strLine))
{
strDescription=strLine.betweenString('=',';');
strDescription.removeTokens("'");
strSymbol=strLine.betweenString(';',0);
sqlString=String("add_symbol('")+strDescription+String("','")+strSymbol+String("','MUTUAL'")+String(");");
sqlStatement.call(sqlString);
}
sqlDb.close();
String pathString("c:\\work\\http\\nasdaq\\");
FindData findData;
StockReader stockReader;
StockQuote stockQuote;
if(findData.findFirst(pathString+String("*.htm")));
{
stockReader.readQuote(pathString+findData.fileName(),stockQuote);
winConsole.read();
while(findData.findNext())
{
stockReader.readQuote(pathString+findData.fileName(),stockQuote);
winConsole.read();
}
}
return FALSE;
}
#endif
#if 0
Block<String> itemStrings;
hostName=cmdLine.betweenString(' ',0);
if(hostName.isNull())return FALSE;
nameFile=hostName;
hostName=hostName.betweenString(0,' ');
if(hostName.isNull())return FALSE;
nameFile=nameFile.betweenString(' ',0);
if(nameFile.isNull())return FALSE;
if(String(nameFile.operator[](0))==String("@"))
{
nameFile=nameFile.substr(1);
// listLoad(nameFile,itemStrings);
// for(int itemIndex=0;itemIndex<itemStrings.size();itemIndex++)open(hostName,itemStrings[itemIndex]);
}
else
{
String strCount;
for(int count=0;count<2000;count++)
{
open(hostName,nameFile);
::sprintf(strCount,"%d",count);
winConsole.writeLine(strCount);
}
}
#endif
// ::sprintf(cmdLine,"http://quote.yahoo.com/d/quotes.csv?s=%s&f=sl1d1t1c1ohgv&e=.csv","intc");
// sqlStatement.call("add_price('INTC',83.8125,'2/13/1998','4:01PM',-1.1875,84.375,84.9375,83.8125,9773400);");
//"INTC",83.8125,"2/13/1998","4:01PM",-1.1875,84.375,84.9375,83.8125,9773400
//symbol,price,date,time,change,low,high,close,volume
// String cmdLine(::GetCommandLine());
// nameFile=cmdLine;
// open(hostName,nameFile);
String strHost;
String strDir;
String strFile;
String strLine;
FileHandle inFile;
inFile.open("e:\\work\\exe\\page.txt");
if(!inFile.isOkay())return false;
inFile.getLine(strLine);
strHost=strLine.betweenString(0,' ');
strDir=strLine.betweenString(' ',0);
while(true)
{
if(!inFile.getLine(strLine))break;
strLine.trimLeft();
::OutputDebugString(strHost+String(" ")+String("http://")+strHost+strDir+String("/")+strLine.betweenString(0,' ')+String(" ")+strLine.betweenString(0,' ')+String("\n"));
}
#if 0