Пример #1
0
 def __init__(self):
     super(QThread, self).__init__()
     self.pref5 = Preferences()
     self.api_root_url = 'http://127.0.0.1:%s/' % self.pref5.getapi_root_port(
     )
     self.post_port = int(self.pref5.getpost_url_port())
     self.bot = CQHttp(api_root=self.api_root_url)
Пример #2
0
 def __init__(self, kd, md, wb):
     super(QThread, self).__init__()
     self.switch_kd = kd
     self.switch_md = md
     self.switch_wb = wb
     self.sched = BlockingScheduler()
     self.weibo_id_array = []
     self.firstcheck_weibo = True
     self.pref3 = Preferences()
     self.api_root_url = 'http://127.0.0.1:%s/' % self.pref3.getapi_root_port(
     )
     self.bot = CQHttp(api_root=self.api_root_url)
     self.version_dict = self.bot.get_version_info()
     self.version = self.version_dict['coolq_edition']
Пример #3
0
 def __init__(self):
     super(Weibo, self).__init__()
     self.pref = Preferences()
     url = str(self.pref.getweibourl())
     header = {
         'User-Agent':
         'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) \
         AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 \
         Safari/537.36'
     }
     form = {
         'containerid': int(self.pref.getweiboid()),
     }
     # 设置response
     self.response = requests.post(url, form, headers=header).json()
     # 设置id序列
     self.IdArray = self.getIdArray()
Пример #4
0
 def clickaccept(self, Dialog):
     pref1 = Preferences()
     # coolq
     self.api_root_port = self.lineEdit_11.text()
     pref1.writeapi_root_port(self.api_root_port)
     self.access_token = self.lineEdit_12.text()
     pref1.writeaccess_token(self.access_token)
     self.secret = self.lineEdit_13.text()
     pref1.writesecret(self.secret)
     self.post_url_port = self.lineEdit_14.text()
     pref1.writepost_url_port(self.post_url_port)
     # qq group
     self.qunid = self.lineEdit.text()
     pref1.writeqqid(self.qunid)
     self.welcome = self.textEdit.toPlainText()
     pref1.writewelcome(self.welcome)
     self.shutword = self.textEdit_2.toPlainText()
     pref1.writeshutwords(self.shutword)
     # idol
     # if not self.lineEdit_2.text():
     #     self.idolname = self.comboBox_3.currentText()
     # else:
     #     self.idolname = self.lineEdit_2.text()
     # pref1.writeidolnick(self.idolname)
     self.idolname = self.comboBox_3.currentText()
     pref1.writeidolname(self.idolname)
     self.idolnick = self.lineEdit_2.text()
     pref1.writeidolnick(self.idolnick)
     if not self.lineEdit_15.text():
         self.roomid = self.lineEdit_3.text()
     else:
         self.roomid = self.lineEdit_15.text()
     pref1.writeroomid(self.roomid)
     # koudai48
     self.kduser = self.lineEdit_4.text()
     self.kdpsd = self.lineEdit_5.text()
     pref1.writekdaccount(self.kduser, self.kdpsd)
     self.kdinterval = self.spinBox.value()
     pref1.writekdinterval(self.kdinterval)
     # modian
     self.proid = self.lineEdit_8.text()
     pref1.writeproid(self.proid)
     self.mdinterval = self.spinBox_2.value()
     pref1.writemdinterval(self.mdinterval)
     # weibo
     self.wbid = self.lineEdit_9.text()
     pref1.writeweiboid(self.wbid)
     self.wbinterval = self.spinBox_3.value()
     pref1.writewbinterval(self.wbinterval)
     # proxy
     self.proxyhttps = self.textEdit_3.toPlainText()
     pref1.writeproxy(self.proxyhttps)
     Dialog.accept()
Пример #5
0
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(637, 350)
        pref2 = Preferences()
        self.gridLayout = QtWidgets.QGridLayout(Dialog)
        self.gridLayout.setObjectName("gridLayout")
        self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel
                                          | QtWidgets.QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")
        self.gridLayout.addWidget(self.buttonBox, 1, 0, 1, 1)
        self.tabWidget = QtWidgets.QTabWidget(Dialog)
        self.tabWidget.setObjectName("tabWidget")
        self.tab_7 = QtWidgets.QWidget()
        self.tab_7.setObjectName("tab_7")
        self.formLayoutWidget_6 = QtWidgets.QWidget(self.tab_7)
        self.formLayoutWidget_6.setGeometry(QtCore.QRect(10, 10, 591, 251))
        self.formLayoutWidget_6.setObjectName("formLayoutWidget_6")
        self.formLayout_7 = QtWidgets.QFormLayout(self.formLayoutWidget_6)
        self.formLayout_7.setContentsMargins(0, 0, 0, 0)
        self.formLayout_7.setObjectName("formLayout_7")
        self.label_20 = QtWidgets.QLabel(self.formLayoutWidget_6)
        self.label_20.setObjectName("label_20")
        self.formLayout_7.setWidget(0, QtWidgets.QFormLayout.LabelRole,
                                    self.label_20)
        self.label_21 = QtWidgets.QLabel(self.formLayoutWidget_6)
        self.label_21.setObjectName("label_21")
        self.formLayout_7.setWidget(1, QtWidgets.QFormLayout.LabelRole,
                                    self.label_21)
        self.label_22 = QtWidgets.QLabel(self.formLayoutWidget_6)
        self.label_22.setObjectName("label_22")
        self.formLayout_7.setWidget(2, QtWidgets.QFormLayout.LabelRole,
                                    self.label_22)
        self.label_23 = QtWidgets.QLabel(self.formLayoutWidget_6)
        self.label_23.setObjectName("label_23")
        self.formLayout_7.setWidget(3, QtWidgets.QFormLayout.LabelRole,
                                    self.label_23)
        self.lineEdit_11 = QtWidgets.QLineEdit(self.formLayoutWidget_6)
        self.lineEdit_11.setAccessibleName("")
        #
        self.lineEdit_11.setText(pref2.getapi_root_port())
        self.lineEdit_11.setObjectName("lineEdit_11")
        self.formLayout_7.setWidget(0, QtWidgets.QFormLayout.FieldRole,
                                    self.lineEdit_11)
        self.lineEdit_12 = QtWidgets.QLineEdit(self.formLayoutWidget_6)
        self.lineEdit_12.setObjectName("lineEdit_12")
        #
        self.lineEdit_12.setText(pref2.getaccess_token())
        self.formLayout_7.setWidget(1, QtWidgets.QFormLayout.FieldRole,
                                    self.lineEdit_12)
        self.lineEdit_13 = QtWidgets.QLineEdit(self.formLayoutWidget_6)
        self.lineEdit_13.setObjectName("lineEdit_13")
        #
        self.lineEdit_13.setText(pref2.getsecret())
        self.formLayout_7.setWidget(2, QtWidgets.QFormLayout.FieldRole,
                                    self.lineEdit_13)
        self.lineEdit_14 = QtWidgets.QLineEdit(self.formLayoutWidget_6)
        self.lineEdit_14.setObjectName("lineEdit_14")
        #
        self.lineEdit_14.setText(pref2.getpost_url_port())
        self.formLayout_7.setWidget(3, QtWidgets.QFormLayout.FieldRole,
                                    self.lineEdit_14)
        self.tabWidget.addTab(self.tab_7, "")
        self.tab_5 = QtWidgets.QWidget()
        self.tab_5.setObjectName("tab_5")
        self.formLayoutWidget = QtWidgets.QWidget(self.tab_5)
        self.formLayoutWidget.setGeometry(QtCore.QRect(10, 10, 591, 251))
        self.formLayoutWidget.setObjectName("formLayoutWidget")
        self.formLayout = QtWidgets.QFormLayout(self.formLayoutWidget)
        self.formLayout.setContentsMargins(0, 0, 0, 0)
        self.formLayout.setObjectName("formLayout")
        self.label = QtWidgets.QLabel(self.formLayoutWidget)
        self.label.setObjectName("label")
        self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole,
                                  self.label)
        self.lineEdit = QtWidgets.QLineEdit(self.formLayoutWidget)
        self.lineEdit.setObjectName("lineEdit")
        #
        self.lineEdit.setText(pref2.getqqid())
        self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole,
                                  self.lineEdit)
        self.label_2 = QtWidgets.QLabel(self.formLayoutWidget)
        self.label_2.setObjectName("label_2")
        self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole,
                                  self.label_2)
        self.textEdit = QtWidgets.QTextEdit(self.formLayoutWidget)
        self.textEdit.setObjectName("textEdit")
        #
        self.textEdit.setText(pref2.getwelcome())
        self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole,
                                  self.textEdit)
        self.label_3 = QtWidgets.QLabel(self.formLayoutWidget)
        self.label_3.setObjectName("label_3")
        self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole,
                                  self.label_3)
        self.textEdit_2 = QtWidgets.QTextEdit(self.formLayoutWidget)
        self.textEdit_2.setObjectName("textEdit_2")
        #
        self.textEdit_2.setText(pref2.getshutwords())
        self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole,
                                  self.textEdit_2)
        self.tabWidget.addTab(self.tab_5, "")
        self.tab = QtWidgets.QWidget()
        self.tab.setObjectName("tab")
        self.gridLayoutWidget = QtWidgets.QWidget(self.tab)
        self.gridLayoutWidget.setGeometry(QtCore.QRect(10, 10, 591, 251))
        self.gridLayoutWidget.setObjectName("gridLayoutWidget")
        self.formLayout_2 = QtWidgets.QFormLayout(self.gridLayoutWidget)
        self.formLayout_2.setContentsMargins(0, 0, 0, 0)
        self.formLayout_2.setObjectName("formLayout_2")
        self.label_4 = QtWidgets.QLabel(self.gridLayoutWidget)
        self.label_4.setObjectName("label_4")
        self.formLayout_2.setWidget(0, QtWidgets.QFormLayout.LabelRole,
                                    self.label_4)
        self.comboBox = QtWidgets.QComboBox(self.gridLayoutWidget)
        self.comboBox.setObjectName("comboBox")
        self.formLayout_2.setWidget(0, QtWidgets.QFormLayout.FieldRole,
                                    self.comboBox)
        self.comboBox.insertItems(0, ['SNH', 'BEJ', 'GNZ', 'SHY', 'CKG'])
        if pref2.getidolgroup():
            self.comboBox.setItemText(0, pref2.getidolgroup())
        #
        # if pref2.getidolgroup():
        #     self.comboBox.setItemText(0, pref2.getidolgroup())
        # else:
        #     self.comboBox.insertItems(0, ['SNH', 'BEJ', 'GNZ', 'SHY', 'CKG'])
        # self.comboBox.currentIndexChanged.connect(lambda : print('you change combox'))
        # end
        self.label_5 = QtWidgets.QLabel(self.gridLayoutWidget)
        self.label_5.setObjectName("label_5")
        self.formLayout_2.setWidget(1, QtWidgets.QFormLayout.LabelRole,
                                    self.label_5)
        self.comboBox_2 = QtWidgets.QComboBox(self.gridLayoutWidget)
        self.comboBox_2.setObjectName("comboBox_2")
        #
        # end
        self.formLayout_2.setWidget(1, QtWidgets.QFormLayout.FieldRole,
                                    self.comboBox_2)
        self.label_6 = QtWidgets.QLabel(self.gridLayoutWidget)
        self.label_6.setObjectName("label_6")
        self.formLayout_2.setWidget(2, QtWidgets.QFormLayout.LabelRole,
                                    self.label_6)
        self.comboBox_3 = QtWidgets.QComboBox(self.gridLayoutWidget)
        self.comboBox_3.setObjectName("comboBox_3")
        #
        self.comboBox_3.addItems(
            list(
                map(lambda e: e[0],
                    self.members.getroomidtuples(
                        self.comboBox.currentText()))))
        if pref2.getidolname():
            self.comboBox_3.setItemText(0, pref2.getidolname())
        #end
        self.formLayout_2.setWidget(2, QtWidgets.QFormLayout.FieldRole,
                                    self.comboBox_3)
        self.label_7 = QtWidgets.QLabel(self.gridLayoutWidget)
        self.label_7.setObjectName("label_7")
        self.formLayout_2.setWidget(3, QtWidgets.QFormLayout.LabelRole,
                                    self.label_7)
        self.lineEdit_2 = QtWidgets.QLineEdit(self.gridLayoutWidget)
        self.lineEdit_2.setObjectName("lineEdit_2")
        #
        self.lineEdit_2.setText(pref2.getidolnick())
        self.formLayout_2.setWidget(3, QtWidgets.QFormLayout.FieldRole,
                                    self.lineEdit_2)
        self.label_8 = QtWidgets.QLabel(self.gridLayoutWidget)
        self.label_8.setObjectName("label_8")
        self.formLayout_2.setWidget(4, QtWidgets.QFormLayout.LabelRole,
                                    self.label_8)
        self.lineEdit_3 = QtWidgets.QLineEdit(self.gridLayoutWidget)
        self.lineEdit_3.setReadOnly(True)
        self.lineEdit_3.setObjectName("lineEdit_3")
        #
        self.lineEdit_3.setText(pref2.getroomid())
        self.formLayout_2.setWidget(4, QtWidgets.QFormLayout.FieldRole,
                                    self.lineEdit_3)
        self.label_24 = QtWidgets.QLabel(self.gridLayoutWidget)
        self.label_24.setObjectName("label_24")
        self.formLayout_2.setWidget(5, QtWidgets.QFormLayout.LabelRole,
                                    self.label_24)
        self.lineEdit_15 = QtWidgets.QLineEdit(self.gridLayoutWidget)
        self.lineEdit_15.setObjectName("lineEdit_15")
        #
        self.lineEdit_15.setText(pref2.getroomid())
        self.formLayout_2.setWidget(5, QtWidgets.QFormLayout.FieldRole,
                                    self.lineEdit_15)
        self.tabWidget.addTab(self.tab, "")
        self.tab_2 = QtWidgets.QWidget()
        self.tab_2.setObjectName("tab_2")
        self.formLayoutWidget_2 = QtWidgets.QWidget(self.tab_2)
        self.formLayoutWidget_2.setGeometry(QtCore.QRect(10, 10, 591, 251))
        self.formLayoutWidget_2.setObjectName("formLayoutWidget_2")
        self.formLayout_3 = QtWidgets.QFormLayout(self.formLayoutWidget_2)
        self.formLayout_3.setContentsMargins(0, 0, 0, 0)
        self.formLayout_3.setObjectName("formLayout_3")
        self.label_9 = QtWidgets.QLabel(self.formLayoutWidget_2)
        self.label_9.setObjectName("label_9")
        self.formLayout_3.setWidget(0, QtWidgets.QFormLayout.LabelRole,
                                    self.label_9)
        self.lineEdit_4 = QtWidgets.QLineEdit(self.formLayoutWidget_2)
        self.lineEdit_4.setObjectName("lineEdit_4")
        #
        self.lineEdit_4.setText(pref2.getkduser())
        self.formLayout_3.setWidget(0, QtWidgets.QFormLayout.FieldRole,
                                    self.lineEdit_4)
        self.label_10 = QtWidgets.QLabel(self.formLayoutWidget_2)
        self.label_10.setObjectName("label_10")
        self.formLayout_3.setWidget(1, QtWidgets.QFormLayout.LabelRole,
                                    self.label_10)
        self.lineEdit_5 = QtWidgets.QLineEdit(self.formLayoutWidget_2)
        self.lineEdit_5.setObjectName("lineEdit_5")
        #
        self.lineEdit_5.setText(pref2.getkdpassword())
        self.formLayout_3.setWidget(1, QtWidgets.QFormLayout.FieldRole,
                                    self.lineEdit_5)
        self.label_11 = QtWidgets.QLabel(self.formLayoutWidget_2)
        self.label_11.setObjectName("label_11")
        self.formLayout_3.setWidget(2, QtWidgets.QFormLayout.LabelRole,
                                    self.label_11)
        self.lineEdit_6 = QtWidgets.QLineEdit(self.formLayoutWidget_2)
        self.lineEdit_6.setReadOnly(True)
        self.lineEdit_6.setObjectName("lineEdit_6")
        #
        self.lineEdit_6.setText(pref2.gettoken())
        self.formLayout_3.setWidget(2, QtWidgets.QFormLayout.FieldRole,
                                    self.lineEdit_6)
        self.label_12 = QtWidgets.QLabel(self.formLayoutWidget_2)
        self.label_12.setObjectName("label_12")
        self.formLayout_3.setWidget(3, QtWidgets.QFormLayout.LabelRole,
                                    self.label_12)
        self.lineEdit_7 = QtWidgets.QLineEdit(self.formLayoutWidget_2)
        self.lineEdit_7.setReadOnly(True)
        self.lineEdit_7.setObjectName("lineEdit_7")
        self.formLayout_3.setWidget(3, QtWidgets.QFormLayout.FieldRole,
                                    self.lineEdit_7)
        self.label_13 = QtWidgets.QLabel(self.formLayoutWidget_2)
        self.label_13.setObjectName("label_13")
        self.formLayout_3.setWidget(4, QtWidgets.QFormLayout.LabelRole,
                                    self.label_13)
        self.spinBox = QtWidgets.QSpinBox(self.formLayoutWidget_2)
        self.spinBox.setMinimum(10)
        self.spinBox.setMaximum(60)
        self.spinBox.setObjectName("spinBox")
        #
        try:
            self.spinBox.setValue(int(pref2.getkdinterval()))
        except:
            pass
        self.formLayout_3.setWidget(4, QtWidgets.QFormLayout.FieldRole,
                                    self.spinBox)
        self.tabWidget.addTab(self.tab_2, "")
        self.tab_3 = QtWidgets.QWidget()
        self.tab_3.setObjectName("tab_3")
        self.formLayoutWidget_3 = QtWidgets.QWidget(self.tab_3)
        self.formLayoutWidget_3.setGeometry(QtCore.QRect(10, 10, 591, 251))
        self.formLayoutWidget_3.setObjectName("formLayoutWidget_3")
        self.formLayout_4 = QtWidgets.QFormLayout(self.formLayoutWidget_3)
        self.formLayout_4.setContentsMargins(0, 0, 0, 0)
        self.formLayout_4.setObjectName("formLayout_4")
        self.label_14 = QtWidgets.QLabel(self.formLayoutWidget_3)
        self.label_14.setObjectName("label_14")
        self.formLayout_4.setWidget(0, QtWidgets.QFormLayout.LabelRole,
                                    self.label_14)
        self.label_15 = QtWidgets.QLabel(self.formLayoutWidget_3)
        self.label_15.setObjectName("label_15")
        self.formLayout_4.setWidget(1, QtWidgets.QFormLayout.LabelRole,
                                    self.label_15)
        self.lineEdit_8 = QtWidgets.QLineEdit(self.formLayoutWidget_3)
        self.lineEdit_8.setObjectName("lineEdit_8")
        #
        self.lineEdit_8.setText(pref2.getproid())
        self.formLayout_4.setWidget(0, QtWidgets.QFormLayout.FieldRole,
                                    self.lineEdit_8)
        self.spinBox_2 = QtWidgets.QSpinBox(self.formLayoutWidget_3)
        self.spinBox_2.setMinimum(10)
        self.spinBox_2.setMaximum(60)
        self.spinBox_2.setObjectName("spinBox_2")
        #
        try:
            self.spinBox_2.setValue(int(pref2.getmdinterval()))
        except:
            pass
        self.formLayout_4.setWidget(1, QtWidgets.QFormLayout.FieldRole,
                                    self.spinBox_2)
        self.tabWidget.addTab(self.tab_3, "")
        self.tab_4 = QtWidgets.QWidget()
        self.tab_4.setObjectName("tab_4")
        self.formLayoutWidget_4 = QtWidgets.QWidget(self.tab_4)
        self.formLayoutWidget_4.setGeometry(QtCore.QRect(10, 10, 591, 251))
        self.formLayoutWidget_4.setObjectName("formLayoutWidget_4")
        self.formLayout_5 = QtWidgets.QFormLayout(self.formLayoutWidget_4)
        self.formLayout_5.setContentsMargins(0, 0, 0, 0)
        self.formLayout_5.setObjectName("formLayout_5")
        self.label_16 = QtWidgets.QLabel(self.formLayoutWidget_4)
        self.label_16.setObjectName("label_16")
        self.formLayout_5.setWidget(0, QtWidgets.QFormLayout.LabelRole,
                                    self.label_16)
        self.label_17 = QtWidgets.QLabel(self.formLayoutWidget_4)
        self.label_17.setObjectName("label_17")
        self.formLayout_5.setWidget(1, QtWidgets.QFormLayout.LabelRole,
                                    self.label_17)
        self.lineEdit_9 = QtWidgets.QLineEdit(self.formLayoutWidget_4)
        self.lineEdit_9.setObjectName("lineEdit_9")
        #
        self.lineEdit_9.setText(pref2.getweiboid())
        self.formLayout_5.setWidget(0, QtWidgets.QFormLayout.FieldRole,
                                    self.lineEdit_9)
        self.lineEdit_10 = QtWidgets.QLineEdit(self.formLayoutWidget_4)
        self.lineEdit_10.setReadOnly(True)
        self.lineEdit_10.setObjectName("lineEdit_10")
        #
        self.lineEdit_10.setText(pref2.getweibourl())
        self.formLayout_5.setWidget(1, QtWidgets.QFormLayout.FieldRole,
                                    self.lineEdit_10)
        self.label_18 = QtWidgets.QLabel(self.formLayoutWidget_4)
        self.label_18.setObjectName("label_18")
        self.formLayout_5.setWidget(2, QtWidgets.QFormLayout.LabelRole,
                                    self.label_18)
        self.spinBox_3 = QtWidgets.QSpinBox(self.formLayoutWidget_4)
        self.spinBox_3.setMinimum(30)
        self.spinBox_3.setMaximum(300)
        self.spinBox_3.setObjectName("spinBox_3")
        #
        try:
            self.spinBox_3.setValue(int(pref2.getwbinterval()))
        except:
            pass
        self.formLayout_5.setWidget(2, QtWidgets.QFormLayout.FieldRole,
                                    self.spinBox_3)
        self.tabWidget.addTab(self.tab_4, "")
        self.tab_6 = QtWidgets.QWidget()
        self.tab_6.setObjectName("tab_6")
        self.formLayoutWidget_5 = QtWidgets.QWidget(self.tab_6)
        self.formLayoutWidget_5.setGeometry(QtCore.QRect(10, 10, 591, 251))
        self.formLayoutWidget_5.setObjectName("formLayoutWidget_5")
        self.formLayout_6 = QtWidgets.QFormLayout(self.formLayoutWidget_5)
        self.formLayout_6.setContentsMargins(0, 0, 0, 0)
        self.formLayout_6.setObjectName("formLayout_6")
        self.label_19 = QtWidgets.QLabel(self.formLayoutWidget_5)
        self.label_19.setObjectName("label_19")
        self.formLayout_6.setWidget(0, QtWidgets.QFormLayout.LabelRole,
                                    self.label_19)
        self.textEdit_3 = QtWidgets.QTextEdit(self.formLayoutWidget_5)
        self.textEdit_3.setObjectName("textEdit_3")
        #
        self.textEdit_3.setText(pref2.getproxy())
        self.formLayout_6.setWidget(0, QtWidgets.QFormLayout.FieldRole,
                                    self.textEdit_3)
        self.tabWidget.addTab(self.tab_6, "")
        self.gridLayout.addWidget(self.tabWidget, 0, 0, 1, 1)

        self.retranslateUi(Dialog)
        self.tabWidget.setCurrentIndex(0)
        # self.buttonBox.accepted.connect(Dialog.accept)
        self.buttonBox.accepted.connect(lambda: self.clickaccept(Dialog))
        self.buttonBox.rejected.connect(Dialog.reject)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

        self.comboBox.currentIndexChanged.connect(lambda: self.changegroup())
        self.comboBox_3.currentIndexChanged.connect(
            lambda: self.changemember())
Пример #6
0
#!/usr/bin/python

from pref import Preferences
import logging

app = Preferences()

MAX_MSG_SIZE = 250
UUID = "0b8d4d80-9bf6-11dd-b89f-0017319b4e54"

# create logger
logger = logging.getLogger()

def log(s):
  logger.debug(s)
Пример #7
0
class Weibo:
    """docstring for Weibo"""
    response = {}
    IdArray = []

    def __init__(self):
        super(Weibo, self).__init__()
        self.pref = Preferences()
        url = str(self.pref.getweibourl())
        header = {
            'User-Agent':
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) \
            AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 \
            Safari/537.36'
        }
        form = {
            'containerid': int(self.pref.getweiboid()),
        }
        # 设置response
        self.response = requests.post(url, form, headers=header).json()
        # 设置id序列
        self.IdArray = self.getIdArray()

    # 去除html标签
    def dr_to_dd(self, dr_str):
        dr = re.compile(r'<[^>]+>', re.S)
        dd = dr.sub('', dr_str)
        return str(dd)

    # 获取id序列
    def getIdArray(self):
        weibo_id_array = []
        cards = self.response['data']['cards']
        for card in cards:
            try:
                weibo_id = card['mblog']['id']
            except Exception as e:
                # 广告位无id,将其置0
                weibo_id_array.append("0")
            else:
                weibo_id_array.append(weibo_id)
        INFO("weibo_id_array", weibo_id_array)
        return weibo_id_array

    # def getData(self, i):
    #     datas = self.response['data']['cards'][i]
    #     return datas

    # 检查id
    def checkId(self, i):
        datas = self.response['data']['cards'][i]
        return str(datas['mblog']['id'])

    # 检查是否为转发微博
    def checkRetweet(self, i):
        datas = self.response['data']['cards'][i]
        if datas['mblog'].get('retweeted_status') is None:
            return False
        else:
            return True

    # 获取微博正文
    def getWeibo(self, i):
        datas = self.response['data']['cards'][i]
        r_weibo = str(datas['mblog']['text'])
        r2d_weibo = self.dr_to_dd(r_weibo)
        return r2d_weibo

    # 获取转发微博
    def getRetweetWeibo(self, i):
        datas = self.response['data']['cards'][i]
        r_retweeetweibo = str(datas['mblog']['raw_text'])
        r2d_retweeetweibo = self.dr_to_dd(r_retweeetweibo)
        return r2d_retweeetweibo

    # 检查是否有图片
    def checkPic(self, i):
        datas = self.response['data']['cards'][i]
        if datas['mblog'].get('pics') is None:
            return False
        else:
            return True

    # 获取图片
    def getPic(self, i):
        datas = self.response['data']['cards'][i]
        picUrlArray = []
        for pic in datas['mblog']['pics']:
            picUrlArray.append(str(pic['url']))
        return picUrlArray

    # 获取微博链接
    def getScheme(self, i):
        datas = self.response['data']['cards'][i]
        # 转换为短网址
        url = get_short_url(str(datas['scheme']))
        return str(url)
Пример #8
0
class ListenGroup(QThread):
    def __init__(self):
        super(QThread, self).__init__()
        self.pref5 = Preferences()
        self.api_root_url = 'http://127.0.0.1:%s/' % self.pref5.getapi_root_port(
        )
        self.post_port = int(self.pref5.getpost_url_port())
        self.bot = CQHttp(api_root=self.api_root_url)

    def run(self):
        @self.bot.on_message('group')
        def handle_msg(context):
            if context['group_id'] in self.pref5.getqqidarray(
            ) and context['user_id'] != context['self_id']:
                # 关键词禁言
                if self.pref5.getshutwordslist():
                    for word in self.pref5.getshutwordslist():
                        if word in context['message']:
                            self.bot.set_group_ban(
                                group_id=context['group_id'],
                                user_id=context['user_id'],
                                duration=30 * 60)
                # 关键词回复
                if context['message'] == '集资' or context[
                        'message'] == 'jz' or context[
                            'message'] == '打卡' or context['message'] == 'dk':
                    jz = ''
                    jz_array = md_init(self.pref5.getproidarray())
                    for jz_dict in jz_array:
                        jz += jz_dict['name'] + '\n' + jz_dict[
                            'url_short'] + '\n'
                    self.bot.send(context, jz)
                elif context['message'] == 'wds20' or context[
                        'message'] == 'jz20' or context[
                            'message'] == 'rank' or context[
                                'message'] == '聚聚榜' or context[
                                    'message'] == 'jzb' or context[
                                        'message'] == '集资榜':
                    rank1_array = rank(1)
                    for rank1_msg in rank1_array:
                        self.bot.send(context, rank1_msg)
                elif context['message'] == 'dkb' or context[
                        'message'] == '打卡榜' or context[
                            'message'] == 'dk20' or context[
                                'message'] == 'dakabang':
                    rank2_array = rank(2)
                    for rank2_msg in rank2_array:
                        self.bot.send(context, rank2_msg)
                elif "独占" in context['message']:
                    dz = ''
                    dz_array = md_init(self.pref5.getproidarray())
                    for dz_dict in dz_array:
                        dz += dz_dict['name'] + '\n' + dz_dict[
                            'url_short'] + '\n'
                    duzhan = "独占请集资" + '\n' + dz
                    self.bot.send(context, duzhan)
                elif context['message'] == '欢迎新人':
                    self.bot.send(context, self.pref5.getwelcome())
                elif context['message'] == '项目进度' or context['message'] == '进度':
                    jd_array = result(self.pref5.getproidarray())
                    jd = ''
                    for jd_msg in jd_array:
                        jd += jd_msg + '\n'
                    self.bot.send(context, jd)

        # 新人加群提醒
        @self.bot.on_event('group_increase')
        def handle_group_increase(context):
            if context['group_id'] == self.pref5.getqqidarray[0]:
                # ret = bot.get_stranger_info(user_id=context['user_id'], no_cache=False)
                # welcome = '欢迎新聚聚:@' + ret['nickname'] + ' 加入本群\n\n' + setting.welcome()
                welcome = [{
                    'type': 'text',
                    'data': {
                        'text': '欢迎新聚聚:'
                    }
                }, {
                    'type': 'at',
                    'data': {
                        'qq': str(context['user_id'])
                    }
                }, {
                    'type': 'text',
                    'data': {
                        'text': ' 加入本群\n\n%s' % self.pref5.getwelcome()
                    }
                }]
                self.bot.send(context, message=welcome, is_raw=True)  # 发送欢迎新人

        # 如果修改了端口,请修改http-API插件的配置文件中对应的post_url
        self.bot.run(host='127.0.0.1', port=self.post_port)
Пример #9
0
class ListenKdMdWb(QThread):
    def __init__(self, kd, md, wb):
        super(QThread, self).__init__()
        self.switch_kd = kd
        self.switch_md = md
        self.switch_wb = wb
        self.sched = BlockingScheduler()
        self.weibo_id_array = []
        self.firstcheck_weibo = True
        self.pref3 = Preferences()
        self.api_root_url = 'http://127.0.0.1:%s/' % self.pref3.getapi_root_port(
        )
        self.bot = CQHttp(api_root=self.api_root_url)
        self.version_dict = self.bot.get_version_info()
        self.version = self.version_dict['coolq_edition']

    def run(self):
        if self.switch_md:
            self.interval_md = int(self.pref3.getmdinterval())
            self.sched.add_job(self.getmodian,
                               'interval',
                               seconds=self.interval_md,
                               misfire_grace_time=10,
                               coalesce=True,
                               max_instances=2)
        if self.switch_wb:
            self.interval_wb = int(self.pref3.getwbinterval())
            self.sched.add_job(self.getweibo,
                               'interval',
                               seconds=self.interval_wb,
                               misfire_grace_time=10,
                               coalesce=True,
                               max_instances=2)
        if self.switch_kd:
            self.interval_kd = int(self.pref3.getkdinterval())
            self.sched.add_job(self.getkoudai,
                               'interval',
                               seconds=self.interval_kd,
                               misfire_grace_time=10,
                               coalesce=True,
                               max_instances=2)
        self.sched.start()

    def getmodian(self):
        try:
            INFO('check modian')
            stampTime = int(time.time())
            msgDict_array = newOrder(stampTime, int(self.interval_md))
            for msgDict in msgDict_array[0:-1]:
                if msgDict:
                    for msg in msgDict['msg']:
                        msg += msgDict['end']
                        print(msg)
                        for grpid in self.pref3.getqqidarray():
                            self.bot.send_group_msg_async(group_id=grpid,
                                                          message=msg,
                                                          auto_escape=False)
                            time.sleep(0.1)
        except Exception as e:
            WARN('error when getModian', e, "modian dict:", msgDict_array[-1])
        finally:
            INFO('modian check completed')

    def getweibo(self):
        try:
            weibo = Weibo()
            INFO('check weibo')
            # 初次启动记录前十条微博id
            if self.firstcheck_weibo is True:
                INFO('first check weibo')
                self.weibo_id_array = weibo.IdArray
                self.firstcheck_weibo = False
            if self.firstcheck_weibo is False:
                # 取最新的前三条微博
                for idcount in range(0, 3):
                    # 广告位微博id为0,忽略
                    if int(weibo.IdArray[idcount]) == 0:
                        continue
                    # 微博id不在记录的id列表里,判断为新微博
                    if weibo.IdArray[idcount] not in self.weibo_id_array:
                        msg = []
                        # 将id计入id列表
                        self.weibo_id_array.append(weibo.IdArray[idcount])
                        # 检查新微博是否是转发
                        if weibo.checkRetweet(idcount):
                            msg.append({
                                'type': 'text',
                                'data': {
                                    'text': '小偶像刚刚转发了一条微博:\n'
                                }
                            })
                            msg.append({
                                'type': 'text',
                                'data': {
                                    'text':
                                    '%s\n' % weibo.getRetweetWeibo(idcount)
                                }
                            })
                        # 原创微博
                        else:
                            msg.append({
                                'type': 'text',
                                'data': {
                                    'text': '小偶像刚刚发了一条新微博:\n'
                                }
                            })
                            msg.append({
                                'type': 'text',
                                'data': {
                                    'text': '%s\n' % weibo.getWeibo(idcount)
                                }
                            })
                            # 检查原创微博是否带图
                            if weibo.checkPic(idcount):
                                # 只取第一张图,pro可以直接发图,air则无
                                msg.append({
                                    'type': 'image',
                                    'data': {
                                        'file': '%s' % weibo.getPic(idcount)[0]
                                    }
                                })
                                # 播报图的总数
                                if len(weibo.getPic(idcount)) > 1:
                                    msg.append({
                                        'type': 'text',
                                        'data': {
                                            'text':
                                            '\n(一共有%d张图喔)\n' %
                                            len(weibo.getPic(idcount))
                                        }
                                    })
                        msg.append({
                            'type': 'text',
                            'data': {
                                'text': '传送门:%s' % weibo.getScheme(idcount)
                            }
                        })
                        for grpid in self.pref3.getqqidarray():
                            self.bot.send_group_msg_async(group_id=grpid,
                                                          message=msg,
                                                          auto_escape=False)
                            time.sleep(0.5)
                        print(msg)
        except Exception as e:
            WARN('error when getWeibo', e)
        finally:
            INFO('weibo check completed')

    def getkoudai(self):
        try:
            INFO('check koudai room')
            koudai = Koudai()
            # 检查是否有新消息
            if koudai.checkNew():
                INFO('have new room msg')
                # 判断酷Q版本
                if self.version == 'air':
                    msgArray = koudai.msgAir()
                elif self.version == 'pro':
                    msgArray = koudai.msgPro()
                # 消息序列反向排序
                msgArray.reverse()
                for msg in msgArray:
                    print(msg)
                    for grpid in self.pref3.getqqidarray():
                        self.bot.send_group_msg_async(group_id=grpid,
                                                      message=msg,
                                                      auto_escape=False)
                        time.sleep(0.5)
        except Exception as e:
            WARN('error when getRoomMsg', e)
            raise e
        finally:
            INFO('koudai check completed')