#include "scrawlerdata.h" #include #include #include #include #include #include using namespace std; SCrawlerData::SCrawlerData() { //platform_name,platform_form,platform_title,article_form,article_parent,article_id,article_nickname,article_title,article_data,article_url,article_hit,article_date,article_order,article_profile,article_profileurl,platform_id,keyword_id,reply_url m_strColumn[ARTICLE_DATA] = "article_data"; m_strColumn[ARTICLE_DATE] = "article_date"; m_strColumn[ARTICLE_FORM] = "article_form"; m_strColumn[ARTICLE_HIT] = "article_hit"; m_strColumn[ARTICLE_ID] = "article_id"; m_strColumn[ARTICLE_NICKNAME] = "article_nickname"; m_strColumn[ARTICLE_ORDER] = "article_order"; m_strColumn[ARTICLE_PARENT] = "article_parent"; m_strColumn[ARTICLE_PROFILE] = "article_profile"; m_strColumn[ARTICLE_PROFILEURL] = "article_profileurl"; m_strColumn[ARTICLE_TITLE] = "article_title"; m_strColumn[ARTICLE_URL] = "article_url"; m_strColumn[KEYWORD_ID] = "keyword_id"; m_strColumn[PLATFORM_FORM] = "platform_form"; m_strColumn[PLATFORM_ID] = "platform_id"; m_strColumn[PLATFORM_NAME] = "platform_name"; m_strColumn[PLATFORM_TITLE] = "platform_title"; m_strColumn[REPLY_URL] = "reply_url"; //m_strColumn[ETC] = "etc"; } SCrawlerData::~SCrawlerData() { clear(); for(int i = 0; i < TOTAL_COUNT; i++) { m_strColumn[i].clear(); } } void SCrawlerData::clear() { for(int i = 0; i < TOTAL_COUNT; i++) { m_strData[i].clear(); } } void SCrawlerData::clear(int _num) { m_strData[_num].clear(); } QString SCrawlerData::getData(int _num) { return m_strData[_num]; } void SCrawlerData::setTable(QString _str) { m_strTable = _str; } void SCrawlerData::setData(QString _str, int _num) { m_strData[_num] = _str; } bool SCrawlerData::sendDB() { QSqlQuery query; QString strQuery; strQuery = "insert into " + m_strTable + "("; for(int i = 0; i < TOTAL_COUNT; i++) { strQuery += (m_strColumn[i] + ","); } strQuery = strQuery.left(strQuery.size() - 1); strQuery += ") VALUES ("; for(int i = 0; i < TOTAL_COUNT; i++) { strQuery += (":" + m_strColumn[i] + ","); } strQuery = strQuery.left(strQuery.size() - 1); strQuery += ")"; query.prepare(strQuery.toUtf8()); for(int i = 0; i < TOTAL_COUNT; i++) { if(i == ARTICLE_ORDER) query.bindValue(QString(":" + m_strColumn[i]), m_strData[i].trimmed().toInt()); else query.bindValue(QString(":" + m_strColumn[i]), m_strData[i].trimmed().toUtf8()); } if (query.exec()==false) { cout << "error : " << query.lastError().text().toStdString(); cout << endl << query.lastQuery().toStdString() << endl ; return false; } return true; } QString SCrawlerData::GetSafeUtf(QString _strData) { QString str; QChar *pch = _strData.data(); for (int i = 0; i < _strData.length(); i++) { if (pch[i].unicode() >= 12593 && pch[i].unicode() <= 12622) str += pch[i]; if (pch[i].unicode() >= 44032 && pch[i].unicode() <= 55203) str += pch[i]; if (pch[i].isDigit() || pch[i].isNumber() || pch[i].isSpace() || pch[i].isLower() || pch[i].isUpper() || pch[i].isSymbol() ) str += pch[i]; } return str; } QStringList SCrawlerData::GetNumber(QString _str) { QString str; QChar *pch = _str.data(); for (int i = 0; i < _str.length(); i++) { if (pch[i].isNumber() || pch[i].isSpace()) str += pch[i]; } return str.trimmed().split(" "); }