새로운 크롤러
git-svn-id: svn://192.168.0.12/source@19 8346c931-da38-4b9b-9d4c-e48b93cbd075
This commit is contained in:
@@ -21,7 +21,7 @@ Widget::Widget(QWidget *parent) : QWidget(parent)
|
||||
QPushButton *pbtStop = new QPushButton("Stop",this);
|
||||
{
|
||||
QObject::connect(pbtStart,SIGNAL(clicked()),this,SLOT(StartButton()));
|
||||
QObject::connect(pbtStop,SIGNAL(clicked()),this,SLOT(StartButton()));
|
||||
QObject::connect(pbtStop,SIGNAL(clicked()),this,SLOT(StopButton()));
|
||||
QObject::connect(pbtRefresh,SIGNAL(clicked()),this,SLOT(RefreshButton()));
|
||||
}
|
||||
|
||||
@@ -34,8 +34,7 @@ Widget::Widget(QWidget *parent) : QWidget(parent)
|
||||
}
|
||||
|
||||
m_pedTime = new QLineEdit(this);
|
||||
m_pedTime->setText(QString("500"));
|
||||
|
||||
m_pedTime->setText(QString("3~10"));
|
||||
{
|
||||
QHBoxLayout *hlayout = new QHBoxLayout;
|
||||
hlayout->addWidget(m_pedTime);
|
||||
@@ -45,9 +44,9 @@ Widget::Widget(QWidget *parent) : QWidget(parent)
|
||||
}
|
||||
|
||||
{
|
||||
QHBoxLayout *hlayout = new QHBoxLayout;
|
||||
for (int i = 0; i < C_CRAWLER_MAX; i++ )
|
||||
hlayout->addWidget(&m_aResultList[i]);
|
||||
QHBoxLayout *hlayout = new QHBoxLayout;
|
||||
m_pResultList = new QListWidget;
|
||||
hlayout->addWidget(m_pResultList);
|
||||
vlayout->addLayout(hlayout);
|
||||
}
|
||||
|
||||
@@ -62,7 +61,7 @@ Widget::Widget(QWidget *parent) : QWidget(parent)
|
||||
m_db.setDatabaseName("concepters");
|
||||
if (!m_db.open())
|
||||
{
|
||||
InsertLog(0,"MySql Error...");
|
||||
InsertLog("MySql Error...");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -78,16 +77,14 @@ Widget::~Widget()
|
||||
m_pNaverCafe->SetParent(0);
|
||||
}
|
||||
|
||||
void Widget::InsertLog(int _nSelect,QString str)
|
||||
void Widget::InsertLog(QString str)
|
||||
{
|
||||
if (_nSelect >= C_CRAWLER_MAX) return;
|
||||
|
||||
QTime time = QTime::currentTime();
|
||||
QString strOut = time.toString("[hh:mm:ss] ") + str;
|
||||
m_aResultList[_nSelect].addItem(strOut);
|
||||
m_pResultList->addItem(strOut);
|
||||
QDate date = QDate::currentDate();
|
||||
|
||||
QFile file(date.toString(Qt::ISODate)+"_"+QString::number(_nSelect)+".log");
|
||||
QFile file(date.toString(Qt::ISODate)+".log");
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append))
|
||||
return;
|
||||
|
||||
@@ -95,22 +92,22 @@ void Widget::InsertLog(int _nSelect,QString str)
|
||||
out << strOut << "\n";
|
||||
file.close();
|
||||
|
||||
if (m_aResultList[_nSelect].count() > 1024)
|
||||
if (m_pResultList->count() > 1024)
|
||||
{
|
||||
m_aResultList[_nSelect].removeItemWidget(m_aResultList[_nSelect].item(0));
|
||||
QListWidgetItem* item = m_aResultList[_nSelect].takeItem(0);
|
||||
m_pResultList->removeItemWidget(m_pResultList->item(0));
|
||||
QListWidgetItem* item = m_pResultList->takeItem(0);
|
||||
delete item;
|
||||
}
|
||||
m_aResultList[_nSelect].setCurrentRow( m_aResultList[_nSelect].count() - 1 );
|
||||
m_aResultList[_nSelect].repaint();
|
||||
m_pResultList->setCurrentRow( m_pResultList->count() - 1 );
|
||||
m_pResultList->repaint();
|
||||
}
|
||||
|
||||
void Widget::StartButton()
|
||||
{
|
||||
{
|
||||
m_timer.stop();
|
||||
m_timer.start(m_pedTime->text().trimmed().toInt());
|
||||
m_timer.start(1000);
|
||||
|
||||
QSqlQuery query;
|
||||
QSqlQuery query;
|
||||
query.exec("UPDATE crawling set state = '" + QString("run") + "' where id = '" + m_pcb->currentData().toString() + "'");
|
||||
query.exec("SELECT _keyword.start,_keyword.end, _keyword.searches,_keyword.authorship,_keyword.id,_datagroup.id "
|
||||
"FROM crawling _crawling INNER JOIN keyword _keyword ON _crawling.keyword_id = _keyword.id "
|
||||
@@ -128,7 +125,7 @@ void Widget::StartButton()
|
||||
query.value(4).toString().trimmed(),// keyword_id
|
||||
query.value(5).toString().trimmed(),
|
||||
1,
|
||||
m_pedTime->text().trimmed().toInt());
|
||||
m_pedTime->text().trimmed());
|
||||
}
|
||||
|
||||
void Widget::StopButton()
|
||||
@@ -142,18 +139,18 @@ void Widget::Update()
|
||||
{
|
||||
if (m_db.open())
|
||||
{
|
||||
InsertLog(0,"MySql Open Error...");
|
||||
InsertLog("MySql Open Error...");
|
||||
m_timer.stop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
int nCount = 0;
|
||||
for (int i = 0 ; i < C_CRAWLER_MAX ; i++)
|
||||
nCount += m_pManage[i]->Update();
|
||||
nCount += m_pManage[0]->Update();
|
||||
if (nCount == C_CRAWLER_MAX)
|
||||
{
|
||||
InsertLog(0,"Finish...");
|
||||
m_timer.stop();
|
||||
InsertLog("Finish...");
|
||||
m_timer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user