代码拉取完成,页面将自动刷新
同步操作将从 EVA/GETTAOBAO 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QJsonDocument>
#include <QJsonParseError>
#include <QFile>
#include <QJsonObject>
#include <QDebug>
#include <QJsonArray>
#include <fstream>
#include <iostream>
#include <QMessageBox>
#include <QThread>
#include <QThreadPool>
#include <QtConcurrent>
#include <QFileDialog>
#include <QFile>
pythonTest test;//python 代码
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),m_keyPath(""),m_id(0),myCmpWork(NULL),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
tableResult table;
table.keyWord = "kkkkkkkkk";
table.result ="rrrrrrrrrrrrrr";
table.url ="uuuuuuuuuuuu";
table.title ="tttttt";
ui->lineEdit_num->setText("3");
//////////////////////////////////////////////
ui->pushButton_cmp->setEnabled(false);
ui->pushButton_cmpstop->setEnabled(false);
ui->pushButton_stop->setEnabled(false);
}
void MainWindow::readText2()
{
ifstream infile;
m_list.clear();
infile.open("list.txt"); //将文件流对象与文件连接起来
assert(infile.is_open()); //若失败,则输出错误消息,并终止程序运行
string s;
QString temp;
while(getline(infile,s))
{
//cout<<s<<endl;
temp = QString::fromStdString(s);
}
infile.close(); //关闭文件输入流
QJsonParseError json_error;
//QJsonDocument jsonDoc(QJsonDocument::fromJson(s.c_str(), &json_error));
// temp = QString::fromStdString(s);
temp=temp.trimmed();
cout<<temp.toStdString().c_str()<<endl;
QJsonDocument jsonDoc(QJsonDocument::fromJson(temp.toStdString().c_str(), &json_error));
if(json_error.error == QJsonParseError::NoError)
{
if(jsonDoc.isArray())
{
QJsonArray rootary = jsonDoc.array();
for (int i = 0 ; i< rootary.size() ; i++)
{
tableResult table;
QString rootObj = rootary.at(i).toString();
table.url = rootObj;
m_list.append(table);
}
}
}
showTable2();
}
void MainWindow::readText()
{
m_listkey.clear();
ifstream infile;
infile.open("list.txt"); //将文件流对象与文件连接起来
assert(infile.is_open()); //若失败,则输出错误消息,并终止程序运行
string s;
QString temp;
while(getline(infile,s))
{
//cout<<s<<endl;
temp = QString::fromStdString(s);
}
infile.close(); //关闭文件输入流
QJsonParseError json_error;
temp=temp.trimmed();
cout<<temp.toStdString().c_str()<<endl;
sqlite lite;
lite.cleakeyData();
QJsonDocument jsonDoc(QJsonDocument::fromJson(temp.toStdString().c_str(), &json_error));
if(json_error.error == QJsonParseError::NoError)
{
if(jsonDoc.isArray())
{
QJsonArray rootary = jsonDoc.array();
for (int i = 0 ; i< rootary.size() ; i++)
{
//QJsonObject rootObj = rootary.at(i).toObject();
QString rootObj = rootary.at(i).toString();
tableResult table;
table.url = rootObj;
m_listkey.append(table);
QString sql ="INSERT INTO key VALUES('"+QString::number(i)+"', '"+table.url+"')";
lite.insertData(sql);
ui->label_info->setText(QString::number(i));
}
}
}
else
qDebug() << json_error.error;
//showTable();
}
MainWindow::~MainWindow()
{
delete ui;
thread.quit();
thread.wait();
/* if(myCmpWork)
{
myCmpWork->quit();
myCmpWork->wait();
}*/
}
//打开匹配表
void MainWindow::showTable()
{
ui->tableWidget->clear();
for(int i =ui->tableWidget->rowCount()-1; i>=0; i--)
{
ui->tableWidget->removeRow(i);
}
ui->tableWidget->setColumnCount(4); //设置列数
ui->tableWidget->horizontalHeader()->setDefaultSectionSize(150);
QStringList header;
header<<tr("关键字")<<tr("")<<tr("")<<tr("");
ui->tableWidget->setHorizontalHeaderLabels(header);
int row_count = ui->tableWidget->rowCount(); //获取表单行数
for (int i = 0; i < m_listkey.size(); i++)
{
ui->tableWidget->insertRow(row_count); //插入新行
QTableWidgetItem *item = new QTableWidgetItem();
QTableWidgetItem *item1 = new QTableWidgetItem();
QTableWidgetItem *item2 = new QTableWidgetItem();
QTableWidgetItem *item3 = new QTableWidgetItem();
//设置对应的图标、文件名称、最后更新时间、对应的类型、文件大小
item->setText(m_listkey[i].keyWord);
item1->setText(m_listkey[i].title);
item2->setText(m_listkey[i].result); //type为调用系统的类型,以后缀来区分
item3->setText(m_listkey[i].url);
ui->tableWidget->setItem(row_count, 0, item);
ui->tableWidget->setItem(row_count, 1, item1);
ui->tableWidget->setItem(row_count, 2, item2);
ui->tableWidget->setItem(row_count, 3, item3);
}
}
//打开匹配表
void MainWindow::showTable2()
{
ui->tableWidget_2->clear();
deleteRoew2();
ui->tableWidget_2->setColumnCount(4); //设置列数
ui->tableWidget_2->horizontalHeader()->setDefaultSectionSize(150);
QStringList header;
header<<"链接"<<tr("标题")<<tr("获取状态")<<tr("匹配度");
ui->tableWidget_2->setHorizontalHeaderLabels(header);
int row_count = ui->tableWidget_2->rowCount(); //获取表单行数
for (int i = 0; i < m_list.size(); i++)
{
ui->tableWidget_2->insertRow(row_count); //插入新行
QTableWidgetItem *item = new QTableWidgetItem();
QTableWidgetItem *item1 = new QTableWidgetItem();
QTableWidgetItem *item2 = new QTableWidgetItem();
QTableWidgetItem *item3 = new QTableWidgetItem();
//设置对应的图标、文件名称、最后更新时间、对应的类型、文件大小
item->setText(m_list[i].url);
item1->setText(m_list[i].title);
item2->setText(m_list[i].keyWord); //type为调用系统的类型,以后缀来区分
item3->setText(m_list[i].result);
ui->tableWidget_2->setItem(row_count, 0, item);
ui->tableWidget_2->setItem(row_count, 1, item1);
ui->tableWidget_2->setItem(row_count, 2, item2);
ui->tableWidget_2->setItem(row_count, 3, item3);
}
}
void MainWindow::refresh()
{
for (int i = 0; i < m_list.size(); i++)
{
QTableWidgetItem *item3 = new QTableWidgetItem();
item3->setText(m_list.at(i).title);
//设置对应的图标、文件名称、最后更新时间、对应的类型、文件大小
//qDebug() << msg<<id;
ui->tableWidget_2->setItem(i, 1, item3);
}
}
void MainWindow::on_pushButton_start_clicked()
{
sqlite lite;
lite.clearData();
if(m_list.size() == 0)
return;
m_id = 0;
ui->pushButton_start->setEnabled(false);
ui->pushButton_stop->setEnabled(true);
myNetWork = new mythead(this);
connect(this, SIGNAL(stoppool()),myNetWork, SLOT(poolstop()));
// myNetWork->getHtml("https://item.taobao.com/item.htm?id=588586438027", 1);
connect(&thread, SIGNAL(started()),myNetWork, SLOT(run()));
connect(myNetWork, SIGNAL(finished()), this, SLOT(deleteLater()));
connect(&thread, SIGNAL(mySignal()), this, SLOT(refresh()));
myNetWork->moveToThread(&thread);
thread.start();
//设置最大线程数为3的一个线程池
}
void MainWindow::deleteRoew()
{
for (int i = ui->tableWidget->rowCount()-1; i >= 0; i--)
{
ui->tableWidget->removeRow(i);
}
// showTable();
}
void MainWindow::deleteRoew2()
{
for (int i = ui->tableWidget_2->rowCount()-1; i >= 0; i--)
{
ui->tableWidget_2->removeRow(i);
}
// showTable();
}
void MainWindow::httpgetid(int id, QString msg)
{
static QMutex mutex;
mutex.lock();
while (m_queue.size()>0)
{
QStringList strUrl =m_queue.front();
m_queue.pop();
// qDebug() <<"ui"<<strUrl.at(0)<<strUrl.at(1);
for (int i = 0; i < ui->tableWidget_2->rowCount(); i++)
{
QString str = ui->tableWidget_2->item(i,0)->text();
//qDebug() <<"ui55"<<m_list.at(i).url;
if(str.contains(strUrl.at(0)))
{
qDebug() <<"ui55ddd"<<strUrl.at(1)<<i;
//m_list[i].title = strUrl.at(1);
QTableWidgetItem *item3 = new QTableWidgetItem();
item3->setText(strUrl.at(1));
ui->tableWidget_2->setItem(i, 1, item3);
QString tilie =strUrl.at(1);
tilie= tilie.replace("-淘宝网","");
tilie= tilie.replace("-tmall.com","");
tilie= tilie.replace("天猫","");
sqlite lite;
if(strUrl.at(0)!="")
{
QString sql ="INSERT INTO website VALUES('"+QString::number(m_id)+"', '"+strUrl.at(0)+"','"+tilie+"', '-1','')";
lite.insertData(sql);
}
break;
}
/*
;
//设置对应的图标、文件名称、最后更新时间、对应的类型、文件大小
//qDebug() << msg<<id;
ui->tableWidget_2->setItem(i, 1, item3);*/
}
m_id++;
ui->label_info->setText(QString("%1共%2").arg(m_id).arg(ui->tableWidget_2->rowCount()));
}
if (m_id == ui->tableWidget_2->rowCount())
{
ui->pushButton_cmp->setEnabled(true);
ui->pushButton_cmpstop->setEnabled(true);
ui->pushButton_stop->setEnabled(false);
}
mutex.unlock();
}
void MainWindow::on_pushButton_stop_clicked()
{
ui->pushButton_start->setEnabled(true);
ui->pushButton_stop->setEnabled(false);
// emit stoppool();
myNetWork->poolstop();
// myNetWork->deleteLater();
// thread.quit();
// thread.wait();
}
//保存数据
void MainWindow::on_pushButton_save_clicked()
{
//保存成JSON给 PYTHON调用
QString path = QFileDialog::getSaveFileName(this,
tr("Open File"),
".",
tr("xlsx Files(*.xlsx)"));
if(!path.isEmpty()) {
//读取之前setPlainText的内容,或直接输出字符串内容QObject::tr()
QString str = test.save(path);
QMessageBox::information(NULL, "Title", str, QMessageBox::Yes, QMessageBox::Yes);
}
}
//打开一个
void MainWindow::on_pushButton_clicked()
{
//删除 list
QFile::remove("list.txt");
QString fileName;
fileName = QFileDialog::getOpenFileName(this,"Open File","","Text File(*.xlsx)");
if(fileName == "")
{
return ;
}
else
{
// QString dd = "";
test.getExcel(fileName);
readText2();
}
}
void MainWindow::on_pushButton_key_clicked()
{
QString fileName;
fileName = QFileDialog::getOpenFileName(this,"Open File","","Text File(*.xlsx)");
if(fileName == "")
{
return ;
}
else
{
m_keyPath = fileName;
ui->label_key->setText(m_keyPath);
QString dd = "";
test.getExcel(fileName);
readText();
}
//删除 list
/* QFile::remove("list.txt");
*/
}
void MainWindow::refreshOK()
{
qDebug()<<"主"<<QThread::currentThreadId();
sqlite lite;
QList<QStringList> kiki = lite.queryData("",7);
ui->label_info->setText(QString("%1").arg(kiki.size()));
// showTableOK();
}
void MainWindow::on_pushButton_cmp_clicked()
{
myNetWork =new mythead(this);
m_listlist.clear();
ui->pushButton_save->setEnabled(false);
ui->pushButton_cmp->setEnabled(false);
//将表存入sqlite
int num = ui->lineEdit_num->text().toInt();
if (num <= 0)
{
QMessageBox::information(NULL, "Title", "匹配数字不能小于等于0", QMessageBox::Yes, QMessageBox::Yes);
return;
}
myCmpWork =new MyNetwork(this);
QObject::connect(myCmpWork, SIGNAL(finished()), myCmpWork, SLOT(deleteLater()));
QObject::connect(myCmpWork, SIGNAL(getid()), this, SLOT(refreshOK()));
QObject::connect(myCmpWork, SIGNAL(finished()), this, SLOT(refreshOKcomplete()));
myCmpWork->start();
}
void MainWindow::refreshOKcomplete()
{
ui->pushButton_save->setEnabled(true);
ui->pushButton_cmp->setEnabled(true);
showTableOK();
}
////
void MainWindow::showTableOK()
{
deleteRoew();
ui->tableWidget->setColumnCount(4); //设置列数
ui->tableWidget->horizontalHeader()->setDefaultSectionSize(150);
QStringList header;
header<<tr("关键字")<<tr("标题")<<tr("相识度")<<tr("id");
ui->tableWidget->setHorizontalHeaderLabels(header);
int row_count = ui->tableWidget->rowCount(); //获取表单行数
sqlite lite;
QList<QStringList> kiki = lite.queryData("",7);
ui->label_info->setText(QString("%1").arg(kiki.size()));
for (int i = 0; i < kiki.size(); i++)
{
ui->tableWidget->insertRow(row_count); //插入新行
QStringList sqlitem = kiki.at(i);
QTableWidgetItem *item = new QTableWidgetItem();
QTableWidgetItem *item1 = new QTableWidgetItem();
QTableWidgetItem *item2 = new QTableWidgetItem();
QTableWidgetItem *item3 = new QTableWidgetItem();
//设置对应的图标、文件名称、最后更新时间、对应的类型、文件大小
item->setText(sqlitem[1]);
item1->setText(sqlitem[4]);
item2->setText(sqlitem[6]); //type为调用系统的类型,以后缀来区分
item3->setText(sqlitem[3]);
ui->tableWidget->setItem(row_count, 0, item);
ui->tableWidget->setItem(row_count, 1, item1);
ui->tableWidget->setItem(row_count, 2, item2);
ui->tableWidget->setItem(row_count, 3, item3);
}
}
void MainWindow::on_pushButton_cmpstop_clicked()
{
ui->pushButton_save->setEnabled(true);
ui->pushButton_cmp->setEnabled(true);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。