Пример #1
0
 def post_selected(self):
     self.msg_box.setText('Posting ......')
     self.msg_box.show()
     if self.up_checkBox.isChecked():
         up = True
         # print "Use Reply Funtion"
     else:
         up = False
         # print "No Use Reply Funtion"
     if not self.txt_sock.isReadOnly():
         sock = str(self.txt_sock.text())
         type_ps = str(self.sock_cbb.currentText())
         data = self.get_data_by_id()
         if not data:
             print "Cant get ID"
         elif 'Sock' in type_ps:
             for dt in data:
                 # print 'put ', dt[0]
                 self.q.put(dt[0])
             for i in range(len(data)):
                 self.th = PostThead(self.q, self.status, self.finish_signal, sock=sock, proxy=None, reply=up)
                 self.th.start()  # start a thread
         elif 'Proxy' in type_ps:
             for dt in data:
                 # print 'put ', dt[0]
                 self.q.put(dt[0])
             for i in range(len(data)):
                 self.th = PostThead(self.q, self.status, self.finish_signal, sock=None, proxy=sock, reply=up)
                 self.th.start()  # start a thread
     else:
         data = self.get_data_by_id()
         if not data:
             print "Cant get ID"
         else:
             for dt in data:
                 # print 'put ', dt[0]
                 self.q.put(dt[0])
             for i in range(len(data)):
                 self.th = PostThead(self.q, self.status, self.finish_signal, sock=None, proxy=None, reply=up)
                 self.th.start()  # start a thread
Пример #2
0
 def post_all(self):
     self.msg_box.setText('Posting ......')
     self.msg_box.show()
     if self.up_checkBox.isChecked():
         up = True
         # print "Use Reply Funtion"
     else:
         up = False
         # print "No Use Reply Funtion"
     sock = str(self.txt_sock.text())
     type_ps = str(self.sock_cbb.currentText())
     data = self.cur.execute('SELECT * FROM Poster;').fetchall()
     if not self.txt_sock.isReadOnly():
         if 'Sock' in type_ps:
             for dt in data:
                 # print 'put ', dt
                 self.q.put(dt)
             for i in range(len(data)):
                 th = PostThead(self.q, self.status, self.finish_signal, sock=sock, proxy=None, reply=up)
                 th.start()  # start a thread
             self.q.join()
         elif 'Proxy' in type_ps:
             for dt in data:
                 # print 'put ', dt
                 self.q.put(dt)
             for i in range(len(data)):
                 th = PostThead(self.q, self.status, self.finish_signal, sock=None, proxy=sock, reply=up)
                 th.start()  # start a thread
     else:
         for dt in data:
             # print 'put ', dt
             self.q.put(dt)
         for i in range(len(data)):
             th = PostThead(self.q, self.status, self.finish_signal, sock=None, proxy=None, reply=up)
             th.start()  # start a thread
         print(self.status)
Пример #3
0
class MainForm(QWidget):
    finish_check_update = pyqtSignal(int, float, str, str)
    update = pyqtSignal()
    status = pyqtSignal(int, str)
    finish_signal = pyqtSignal()

    def __init__(self):
        self.body = None
        self.subject = None
        self.q = Queue()
        self.new_version = None
        self.update_link = None
        self.md5 = None
        self.force = 0
        self.up = False
        self.path = os.getcwd()
        self.msg_box = QMessageBox()

        super(MainForm, self).__init__()
        uic.loadUi(resource_path("xxx.ui"), self)

        # init form
        self.add_forum = AddForum(self.update)
        self.browser = Rqbrowser()
        self.addpost = AddPost()
        self.finish_check_update.connect(self.finished)

        width = QtGui.QDesktopWidget().width() * 0.5
        height = QtGui.QDesktopWidget().height() * 0.5
        screen_rect = QtGui.QDesktopWidget().availableGeometry()
        x, y = (
            (screen_rect.width() - screen_rect.x() - width) / 2, (screen_rect.height() - screen_rect.y() - height) / 2)
        self.setGeometry(x, y, width, height)

        # add and resize pictures

        self.setWindowTitle('Cherry Poster')
        # self.report_button.clicked.connect(self.post_finish)
        self.report_button.setIcon(QtGui.QIcon(resource_path('report.png')))
        self.report_button.setIconSize(QtCore.QSize(24, 24))

        self.add_forum_button.clicked.connect(self.add_forum.show)
        self.add_forum_button.setIcon(QtGui.QIcon(resource_path('add.png')))
        self.add_forum_button.setIconSize(QtCore.QSize(24, 24))

        self.post_category.clicked.connect(self.get_category)
        self.post_category.setIcon(QtGui.QIcon(resource_path('cate.png')))
        self.post_category.setIconSize(QtCore.QSize(24, 24))

        self.delete_button.clicked.connect(self.delete_forum)
        self.delete_button.setIcon(QtGui.QIcon(resource_path('delete.png')))
        self.delete_button.setIconSize(QtCore.QSize(24, 24))

        self.change_button.clicked.connect(self.update_all)
        self.change_button.setIcon(QtGui.QIcon(resource_path('refresh.png')))
        self.change_button.setIconSize(QtCore.QSize(24, 24))

        self.post_button.clicked.connect(self.post_selected)
        self.post_button.setIcon(QtGui.QIcon(resource_path('check.png')))
        self.post_button.setIconSize(QtCore.QSize(24, 24))

        self.add_post_button.clicked.connect(self.addpost.show)
        self.add_post_button.setIcon(QtGui.QIcon(resource_path('add_post.png')))
        self.add_post_button.setIconSize(QtCore.QSize(24, 24))

        self.post_all_button.clicked.connect(self.post_all)
        self.post_all_button.setIcon(QtGui.QIcon(resource_path('all.png')))
        self.post_all_button.setIconSize(QtCore.QSize(24, 24))

        self.status.connect(self.update_status)
        self.finish_signal.connect(self.post_finish)

        # Table with model
        self.model = QtSql.QSqlTableModel(self)
        self.model.setTable("Poster")
        self.model.setEditStrategy(QtSql.QSqlTableModel.OnManualSubmit)
        self.model.select()
        self.data_table.setModel(self.model)
        self.data_table.setSelectionBehavior(Qt.QAbstractItemView.SelectRows)
        self.data_table.show()
        self.cur = con.cursor()
        self.get_category()
        self.q = Queue()

        self.checkbox.stateChanged.connect(self.checkbox_check)
        self.up_checkBox.stateChanged.connect(self.up_checkbox_check)
        self.update.connect(self.update_all)

        self.data_table.resizeColumnsToContents()
        # Turn check update on or off
        self.check_update()
        self.txt_sock.setReadOnly(True)
        self.sock_cbb.setEnabled(False)

    def check_update(self):
        self.check_thread = CheckNewVersion(self.finish_check_update)
        self.check_thread.start()

    def post_finish(self):
        self.cur.execute("SELECT * FROM Poster WHERE STATUS='Done';")
        result = self.cur.fetchall()
        done = len(result)
        self.cur.execute("SELECT * FROM Poster;")
        result2 = self.cur.fetchall()
        count = len(result2)
        self.msg_box.setText('Finish {0}/{1}'.format(str(done), str(count)))
        self.msg_box.show()

    def up_checkbox_check(self, state):
        """

        :param state:
        :return:
        """
        if state == QtCore.Qt.Checked:
            self.up = True
            print('Checked')
            return True
        else:
            self.up = False
            print('Not Check')
            return False

    def checkbox_check(self, state):
        if state == QtCore.Qt.Checked:
            self.txt_sock.setReadOnly(False)
            self.sock_cbb.setEnabled(True)
            return True
        else:
            self.txt_sock.setReadOnly(True)
            self.sock_cbb.setEnabled(False)
            return False

    def normal_update(self):
        w = write_bat_file(self.update_link, self.md5)
        if w:
            os.system('update.bat')
            time.sleep(0.5)
            self.close()
            sys.exit(1)

    def report(self):
        # Todo : make a report session .
        pass
        # self.update_status()

    def get_category(self):
        cate = self.cur.execute('SELECT CATEGORY FROM Poster')
        for ca in set(cate):
            self.comboBox.addItem(ca[0])

    def update_all(self):
        con.commit()
        self.model.submitAll()
        self.model.select()
        self.get_category()

    def update_status(self, idm, status):
        # for key, value in self.status.iteritems():
        self.cur.execute('UPDATE Poster SET STATUS=? WHERE ID=?;', (str(status), int(idm)))
        # con.commit()
        # self.msg_box.setText('Finish %d/%d') % (done, count)
        self.update_all()
        # self.msg_box.show()
        print('Update Done')

    def select_ids(self):
        id_selected = []
        indexes = self.data_table.selectionModel().selectedRows()
        for index in sorted(indexes):
            # print index
            ids = self.model.index(index.row(), 0).data()
            idx = str(ids.toString())
            id_selected.append(idx)
        return id_selected

    def get_data_by_id(self):
        data = []
        ids = self.select_ids()
        if not ids:
            self.msg_box.setText("You haven't choose any thing !")
            self.msg_box.show()
        else:
            for i in ids:
                try:
                    dt = self.cur.execute('SELECT * FROM Poster WHERE ID=%s;' % i).fetchall()
                    data.append(dt)
                except sqlite3.Error:
                    self.msg_box.setText('Database Error')
                    self.msg_box.show()
                    break
            return data

    def delete_forum(self):
        self.model.removeRow(self.data_table.currentIndex().row())
        self.update_all()

    def post_selected(self):
        self.msg_box.setText('Posting ......')
        self.msg_box.show()
        if self.up_checkBox.isChecked():
            up = True
            # print "Use Reply Funtion"
        else:
            up = False
            # print "No Use Reply Funtion"
        if not self.txt_sock.isReadOnly():
            sock = str(self.txt_sock.text())
            type_ps = str(self.sock_cbb.currentText())
            data = self.get_data_by_id()
            if not data:
                print "Cant get ID"
            elif 'Sock' in type_ps:
                for dt in data:
                    # print 'put ', dt[0]
                    self.q.put(dt[0])
                for i in range(len(data)):
                    self.th = PostThead(self.q, self.status, self.finish_signal, sock=sock, proxy=None, reply=up)
                    self.th.start()  # start a thread
            elif 'Proxy' in type_ps:
                for dt in data:
                    # print 'put ', dt[0]
                    self.q.put(dt[0])
                for i in range(len(data)):
                    self.th = PostThead(self.q, self.status, self.finish_signal, sock=None, proxy=sock, reply=up)
                    self.th.start()  # start a thread
        else:
            data = self.get_data_by_id()
            if not data:
                print "Cant get ID"
            else:
                for dt in data:
                    # print 'put ', dt[0]
                    self.q.put(dt[0])
                for i in range(len(data)):
                    self.th = PostThead(self.q, self.status, self.finish_signal, sock=None, proxy=None, reply=up)
                    self.th.start()  # start a thread

    def post_all(self):
        self.msg_box.setText('Posting ......')
        self.msg_box.show()
        if self.up_checkBox.isChecked():
            up = True
            # print "Use Reply Funtion"
        else:
            up = False
            # print "No Use Reply Funtion"
        sock = str(self.txt_sock.text())
        type_ps = str(self.sock_cbb.currentText())
        data = self.cur.execute('SELECT * FROM Poster;').fetchall()
        if not self.txt_sock.isReadOnly():
            if 'Sock' in type_ps:
                for dt in data:
                    # print 'put ', dt
                    self.q.put(dt)
                for i in range(len(data)):
                    th = PostThead(self.q, self.status, self.finish_signal, sock=sock, proxy=None, reply=up)
                    th.start()  # start a thread
                self.q.join()
            elif 'Proxy' in type_ps:
                for dt in data:
                    # print 'put ', dt
                    self.q.put(dt)
                for i in range(len(data)):
                    th = PostThead(self.q, self.status, self.finish_signal, sock=None, proxy=sock, reply=up)
                    th.start()  # start a thread
        else:
            for dt in data:
                # print 'put ', dt
                self.q.put(dt)
            for i in range(len(data)):
                th = PostThead(self.q, self.status, self.finish_signal, sock=None, proxy=None, reply=up)
                th.start()  # start a thread
            print(self.status)

    def finished(self, force, newversion, updatelink, md5):
        self.force = force
        self.new_version = newversion
        self.update_link = str(updatelink)
        self.md5 = str(md5)
        print(self.force, self.new_version, self.update_link, self.md5)
        if self.force == 1:
            self.force_update()
        if self.new_version == 0:
            self.btn_new_version.setText("Program is up to date")
        else:
            self.update_link = self.update_link
            self.btn_new_version.setText("Update to version %s " % self.new_version)
            self.btn_new_version.clicked.connect(self.normal_update)

    def force_update(self):
        w = write_bat_file(self.update_link, self.md5)
        if w:
            os.system('update.bat')
            time.sleep(0.5)
            self.close()
            sys.exit(0)