分析PA日志程序

来源:互联网 发布:mac校园网客户端 编辑:程序博客网 时间:2024/06/08 17:22
#include<iostream>#include<string>#include<fstream>using namespace std;inline void  deleteItem(string& text){int k=-1;for(int i=0;i<text.length();++i){if(text[i]=='?')k=k+1;elsetext[i-k-1]=text[i];}text.resize(text.length()-(k+1),'?');}inline string getTitle(string& line){int before=line.find("<title>");int after=line.find("</title>");string str=(before!=-1&&after!=-1)?line.substr(before+7,after-before-7):" ";deleteItem(str);return str;} inline string getContentTitle(string& line){int before=line.find("<content-title>");        int after=line.find("</content-title>");        string str=(before!=-1&&after!=-1)?line.substr(before+15,after-before-15):" ";deleteItem(str);return str;}inline string getContent(string& line){int before=line.find("<major>");        int after=line.find("</major>");        string str=(before!=-1&&after!=-1)?line.substr(before+7,after-before-7):" ";deleteItem(str);return str;}int main(){string newLine;string oldLine;string urlText;string newTitle;string oldTitle;string newContentTitle;string oldContentTitle;string newContent;string oldContent;int urlBefore=0;int urlAfter=0;ifstream inNew("log_pdf_new_PA_1_sendData_20110920");//ifstream inNew("newTestt.log");if(!inNew){cout<<"log_pdf_new_PA_1_sendData_20110920 open failed!"<<endl; return 1;}ifstream temp;ofstream outLog("diff_log_20110920.log",ios::app);if(!outLog){cout<<"diff_log_20110920.log open failed!"<<endl; return 1;}ofstream sameList("sameList_PA_log_20110920",ios::app);if(!sameList){cout<<"sameList open failed!"<<endl; return 1;}        ofstream differentList("differentList_PA_log_20110920",ios::app);        if(!differentList){cout<<"differentList open failed!"<<endl; return 1;}while(getline(inNew,newLine)){urlBefore=newLine.find("<xpage url=");urlAfter=newLine.find("pageinfo");if(urlBefore==-1||urlAfter==-1) continue;urlText=newLine.substr(urlBefore+12,urlAfter-urlBefore-29);if(urlText.find("www.area-34.")!=string::npos)continue;if(urlText.find("www.epcos.com")!=string::npos)continue;if(urlText.find("epaper.dqdaily.com")!=string::npos)continue;cout<<"正在分析文档:"<<urlText<<"..."<<endl;string execute="grep '"+urlText+"' log_pdf_old_PA_1_sendData_20110920 > temp.txt";//string execute="grep '"+urlText+"' oldTestt.log > temp.txt";system(execute.c_str());temp.clear();temp.close();temp.open("temp.txt");if(!temp){cout<<"temp.txt open failed!"<<endl; return 1;}getline(temp,oldLine);if(newLine!=oldLine){newTitle=getTitle(newLine);// cout<<"新标题:"<<newTitle<<endl;oldTitle=getTitle(oldLine);// cout<<"旧标题:"<<oldTitle<<endl;newContentTitle=getContentTitle(newLine);// cout<<"新内容标题:"<<newContentTitle<<endl;oldContentTitle=getContentTitle(oldLine);// cout<<"旧内容标题:"<<oldContentTitle<<endl;newContent=getContent(newLine);// cout<<"新内容:"<<newContent<<endl;oldContent=getContent(oldLine);// cout<<"旧内容:"<<oldContent<<endl;if(newTitle==oldTitle && newContentTitle==oldContentTitle && newContent==oldContent){cout<<urlText+"一样----?"<<endl;sameList<<urlText<<endl;}else{differentList<<urlText<<endl;cout<<urlText+"!!!!!!!!!!!!!!!!!!!!不一样!!!!!!!!!!!!!!!!"<<endl;//if(oldLine==""){outLog<<"没有找到旧版本日志"<<urlText<<endl; }outLog<<urlText<<endl;if(newTitle!=oldTitle){                                outLog<<"newTitle:"<<newTitle<<endl;                                outLog<<"oldTitle:"<<oldTitle<<endl;}if(newContentTitle!=oldContentTitle){outLog<<"newContentTitle:"<<newContentTitle<<endl;outLog<<"oldContentTitle:"<<oldContentTitle<<endl;}if(newContent!=oldContent){outLog<<"newContent:"<<newContent<<endl;outLog<<"oldContent:"<<oldContent<<endl;}}}else{cout<<urlText+"一样"<<endl;//newTitle=getTitle(newLine);cout<<"新标题:"<<newTitle<<endl;  //                      oldTitle=getTitle(oldLine);cout<<"旧标题:"<<oldTitle<<endl;    //                    newContentTitle=getContentTitle(newLine);cout<<"新内容标题:"<<newContentTitle<<endl;      //                  oldContentTitle=getContentTitle(oldLine);cout<<"旧内容标题:"<<oldContentTitle<<endl;        //                newContent=getContent(newLine);cout<<"新内容:"<<newContent<<endl;          //              oldContent=getContent(oldLine);cout<<"旧内容:"<<oldContent<<endl;sameList<<urlText<<endl;}cout<<"文档"<<urlText<<"分析完成!"<<endl<<endl;}sameList.clear();sameList.close();differentList.clear();differentList.close();temp.clear();temp.close();outLog.clear();outLog.close();inNew.clear();inNew.close();return 0;}

 
原创粉丝点击