# include <iostream>
# include <fstream>
# include <string>
# include <cstdlib>
# include <ctime>
# include "db.h"
# include "pageDown.h"
# include "match.h"
using namespace std;
int main()
{
string urlhead="http://stockdata.stock.hexun.com/";
string matchContenA1="总股本(万股)";
string matchContenA2="总资产(亿元)";
string matchContenA3="流通A股(万股)";
string matchContenB1="总股本";
string matchContenB3="流通股";
string name ,code;
string sqlheadA="insert into stock_info3(code,name,tshare,cshare ,tmoney)values('";
string sqlheadB="insert into stock_info3(code,name,tshare,cshare )values('";
ifstream infile;
cout<<"herr"<<endl;
infile.open("shjs.txt");
if(!infile)
return 0;
DB db=DB("121.15.171.69","stock","hello","stock");
//string sql;
if(db.connect("GBK"))
cout<<"Connet is ok"<<endl;
else
{
exit(1);
cout<<"false"<<endl;
}
while(!infile.eof())
{
cout<<"fg"<<endl;
infile>>name;
infile>>code;
cout<<code<<"code"<<endl;
int flag=atoi(code.c_str());
cout<<"flag"<<flag<<endl;
if(flag/10000==60||flag/10000==90)
{
string url=urlhead+code+".shtml";
cout<<"url:"<<url<<endl;
string pageContent=GetPageContent(url);
if(pageContent.length()>0)
{
if(flag/10000==60)
{
string matchCaptitalResult=GetMatchContent(pageContent,matchContenA1);
cout<<"matchCaptitalResult"<<matchCaptitalResult<<endl;
string matchMoneyResult=GetMatchContent(pageContent,matchContenA2);
cout<<" matchMoneyResult"<< matchMoneyResult<<endl;
string matchCurrentCaptital=GetMatchContent(pageContent,matchContenA3);
cout<<"matchCurrentCaptital"<<matchCurrentCaptital<<endl;
//write database
string sql;
sql=sqlheadA;
sql+="SH"+code;
sql+="','";
sql+=name;
sql+="','";
sql+=matchCaptitalResult;
sql+="','";
sql+=matchCurrentCaptital;
sql+="','";
sql+=matchMoneyResult;
sql+="')";
cout<<"sql"<<sql<<endl;
if(db.update(sql))
cout<<"OK insaert"<<endl;
}
if(flag/10000==90)
{
string matchCaptitalResult=GetMatchContent(pageContent,matchContenB1);
cout<<"matchCaptitalResult"<<matchCaptitalResult<<endl;
//string matchMoneyResult=GetMatchContent(pageContent,matchContenA2);
//cout<<" matchMoneyResult"<< matchMoneyResult<<endl;
string matchCurrentCaptital=GetMatchContent(pageContent,matchContenB3);
cout<<"matchCurrentCaptital"<<matchCurrentCaptital<<endl;
//write database
string sql;
sql=sqlheadB;
sql+="SH"+code;
sql+="','";
sql+=name;
sql+="','";
sql+=matchCaptitalResult;
sql+="','";
sql+=matchCurrentCaptital;
sql+="')";
cout<<"sql"<<sql<<endl;
if(db.update(sql))
cout<<"OK insaert"<<endl;
}
}
}
}
infile.close();
infile.open("szjs.txt");
if(!infile)
return 0;
while(!infile.eof())
{
infile>>name;
infile>>code;
int flag=atoi(code.c_str());
if(flag/10000==0||flag/10000==20)
{
string url=urlhead+code+".shtml";
string pageContent=GetPageContent(url);
if(pageContent.length()>0)
{
if(flag/10000==0)
{
string matchCaptitalResult=GetMatchContent(pageContent,matchContenA1);
cout<<"matchCaptitalResult"<<matchCaptitalResult<<endl;
string matchMoneyResult=GetMatchContent(pageContent,matchContenA2);
cout<<" matchMoneyResult"<< matchMoneyResult<<endl;
string matchCurrentCaptital=GetMatchContent(pageContent,matchContenA3);
cout<<"matchCurrentCaptital"<<matchCurrentCaptital<<endl;
//write database
string sql;
sql=sqlheadA;
sql+="SH"+code;
sql+="','";
sql+=name;
sql+="','";
sql+=matchCaptitalResult;
sql+="','";
sql+=matchCurrentCaptital;
sql+="','";
sql+=matchMoneyResult;
sql+="')";
cout<<"sql"<<sql<<endl;
if(db.update(sql))
cout<<"OK insaert"<<endl;
}
if(flag/10000==20)
{
string matchCaptitalResult=GetMatchContent(pageContent,matchContenB1);
cout<<"matchCaptitalResult"<<matchCaptitalResult<<endl;
//string matchMoneyResult=GetMatchContent(pageContent,matchContenA2);
//cout<<" matchMoneyResult"<< matchMoneyResult<<endl;
string matchCurrentCaptital=GetMatchContent(pageContent,matchContenB3);
cout<<"matchCurrentCaptital"<<matchCurrentCaptital<<endl;
//write database
string sql;
sql=sqlheadB;
sql+="SH"+code;
sql+="','";
sql+=name;
sql+="','";
sql+=matchCaptitalResult;
sql+="','";
sql+=matchCurrentCaptital;
sql+="')";
cout<<"sql"<<sql<<endl;
if(db.update(sql))
cout<<"OK insaert"<<endl;
}
}
}
}
db.close();
infile.close();
return 0;
}