Beispiel #1
0
    def user_commit_register(self):
        """ 用户提交注册 """
        if self.register_password_1.text() != self.register_password_2.text():
            QMessageBox.information(self, "错误", "两次输入密码不一致!")
            return
        self.register_button.clicked.disconnect()  # 关闭注册点击链接
        self.text_animation_timer.start(500)  # 按钮文字显示状态
        md5_hash = md5()
        md5_hash.update(self.register_password_1.text().encode("utf-8"))
        register_dict = {
            "phone": self.register_phone.text(),
            "nickname": self.register_nickname.text(),
            "password": md5_hash.hexdigest(),
            "input_code": self.register_code.text(),
            "code_uuid": self._code_uuid
        }

        print(register_dict)
        multi_data = generate_multipart_data(register_dict)
        app = QApplication.instance()
        network_manager = getattr(app, "_network")

        url = SERVER + "register/"
        request = QNetworkRequest(url=QUrl(url))
        # request.setHeader(QNetworkRequest.ContentTypeHeader, "multipart/form-data; boundary=%s" % multi_data.boundary())  # 设置后服务器无法找到边界报400
        reply = network_manager.post(request, multi_data)
        reply.finished.connect(self.user_register_back)
        multi_data.setParent(reply)
Beispiel #2
0
    def user_commit_login(self):
        """ 用户提交登录 """
        self.login_button.clicked.disconnect()  # 关闭登录点击链接
        # 改变登录按钮文字显示状态
        self.text_animation_timer.start(800)

        md5_hash = md5()
        md5_hash.update(self.login_password.text().encode("utf-8"))

        app = QApplication.instance()
        network_manager = getattr(app, "_network")

        text_dict = {
            "phone": self.login_phone.text(),
            "password": md5_hash.hexdigest(),
            "input_code": self.login_code.text(),
            "code_uuid": self._code_uuid
        }
        multi_data = generate_multipart_data(text_dict)

        url = SERVER + "login/"
        request = QNetworkRequest(url=QUrl(url))
        # request.setHeader(QNetworkRequest.ContentTypeHeader, "multipart/form-data; boundary=%s" % multi_data.boundary())  # 设置后服务器无法找到边界报400
        reply = network_manager.post(request, multi_data)
        reply.finished.connect(self.user_login_back)
        multi_data.setParent(reply)
Beispiel #3
0
    def get_rank_source_file(self):
        """ 获取日持仓排名数据zip源文件保存至本地 """
        if self.date is None:
            raise DateValueError("请先使用`set_date`设置`DCESpider`日期.")
        url = "http://www.dce.com.cn/publicweb/quotesdata/exportMemberDealPosiQuotesBatchData.html"
        form_params = {
            'memberDealPosiQuotes.variety': 'a',
            'memberDealPosiQuotes.trade_type': '0',
            'year': str(self.date.year),
            'month': str(self.date.month - 1),
            'day': self.date.strftime("%d"),
            'contract.contract_id': 'a2009',
            'contract.variety_id': 'a',
            'batchExportFlag': 'batch'
        }
        form_data = generate_multipart_data(text_dict=form_params)

        network_manager = getattr(qApp, "_network")

        request = QNetworkRequest(QUrl(url))
        request.setHeader(QNetworkRequest.UserAgentHeader,
                          random.choice(USER_AGENTS))
        reply = network_manager.post(request, form_data)
        reply.finished.connect(self.rank_source_file_reply)
        form_data.setParent(reply)
    def send_local_report(self, body_data):
        """ 上传本地报告文件 """
        def create_report_reply():
            if reply.error():
                message = "创建报告失败!"
            else:
                message = "创建报告成功!"
                self.local_file_edit.clear()
                self.clear_relative_variety()
            reply.deleteLater()
            p = InformationPopup(message, self)
            p.exec_()

        # 文件信息
        file = QFile(self.local_file_path)
        file.open(QFile.ReadOnly)
        file_dict = {"report_file": file}
        # 其他信息
        text_dict = body_data.copy()
        multipart_data = generate_multipart_data(text_dict, file_dict)
        url = SERVER_API + 'report-file/'
        request = QNetworkRequest(QUrl(url))
        request.setRawHeader("Authorization".encode("utf-8"),
                             get_user_token().encode("utf-8"))
        network_manager = getattr(qApp, "_network")
        reply = network_manager.post(request, multipart_data)
        reply.finished.connect(create_report_reply)
        multipart_data.setParent(reply)
 def create_new_advertisement(self):
     """ 确认创建新的广告 """
     ad_params = self.get_new_advertisement_params()
     if not all([ad_params["image"], ad_params["title"]]):
         p = InformationPopup("标题和图片不能为空!", self)
         p.exec_()
         return
     self.create_button.setEnabled(False)
     image_file = QFile(ad_params["image"])
     image_file.open(QFile.ReadOnly)
     file_dict = {"image": image_file}
     if ad_params["filepath"]:
         pdf_file = QFile(ad_params["filepath"])
         pdf_file.open(QFile.ReadOnly)
         file_dict["pdf_file"] = pdf_file
     text_dict = ad_params.copy()
     multipart_data = generate_multipart_data(text_dict, file_dict)
     # close后便无法生成multipartData
     # image_file.close()
     # if pdf_file:
     #     pdf_file.close()
     url = SERVER_API + 'advertisement/'
     request = QNetworkRequest(QUrl(url))
     request.setRawHeader("Authorization".encode("utf-8"),
                          get_user_token().encode("utf-8"))
     network_manager = getattr(qApp, "_network")
     reply = network_manager.post(request, multipart_data)
     reply.finished.connect(self.create_advertisement_reply)
     multipart_data.setParent(reply)
    def user_commit_login(self):
        """ 用户登录 """
        self.remember_checked_handler()  # 处理是否记住密码
        self.remember_login_handler()  # 处理是否自动登录

        config_path = os.path.join(BASE_DIR, "dawn/client.ini")
        client_configs = QSettings(config_path, QSettings.IniFormat)

        phone = self.login_widget.phone_edit.text().strip()
        password = self.login_widget.password_edit.text().strip()
        user_dict = {
            "phone":
            base64.b64encode(phone.encode('utf-8')).decode('utf-8'),  # 加密
            "password":
            base64.b64encode(password.encode('utf-8')).decode('utf-8'),
            "input_code": self.login_widget.image_code_edit.text().strip(),
            "code_uuid": self._code_uuid,
            "client_uuid": client_configs.value("TOKEN/UUID")
        }
        self.login_widget.login_button.disconnect()  # 断开信号
        if not self.text_animation_timer.isActive():
            self.text_animation_timer.start(400)

        multi_data = generate_multipart_data(user_dict)

        network_manager = getattr(qApp, "_network")

        url = SERVER_API + "login/"
        request = QNetworkRequest(QUrl(url))

        reply = network_manager.post(request, multi_data)
        reply.finished.connect(self.user_login_back)
        multi_data.setParent(reply)
    def user_commit_register(self):
        """ 用户注册 """
        phone = self.register_widget.phone_edit.text().strip()
        if not re.match(r'^[1][3-9][0-9]{9}$', phone):
            self.register_widget.phone_error.setText("手机号格式有误!")
            return
        email = self.register_widget.email_edit.text().strip()
        if not re.match(
                r'^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$',
                email):
            self.register_widget.email_error.setText("请填写正确的邮箱!")
            return
        password_0 = self.register_widget.password_edit_0.text().strip()
        password_1 = self.register_widget.password_edit_1.text().strip()
        if not re.match(r'^[a-zA-Z_0-9!#.]{6,20}$', password_0):
            self.register_widget.password_error_0.setText(
                "密码仅允许大小写字母数字的6-20个字符组成")
            return
        if password_0 != password_1:
            self.register_widget.password_error_1.setText("两次输入密码不一致!")
            return
        config_path = os.path.join(BASE_DIR, "dawn/client.ini")
        client_configs = QSettings(config_path, QSettings.IniFormat)

        # 获取注册信息
        register_dict = {
            "username":
            self.register_widget.username_edit.text().strip(),
            "phone":
            base64.b64encode(phone.encode('utf-8')).decode('utf-8'),
            "email":
            self.register_widget.email_edit.text().strip(),
            "password":
            base64.b64encode(password_1.encode('utf-8')).decode('utf-8'),
            "client_token":
            client_configs.value('TOKEN/UUID'),
            "input_code":
            self.register_widget.image_code_edit.text().strip(),
            "code_uuid":
            self._code_uuid,
            "client_uuid":
            client_configs.value("TOKEN/UUID")
        }
        self.register_widget.register_button.disconnect()  # 屏蔽再次点击信号

        if not self.text_animation_timer.isActive():
            self.text_animation_timer.start(400)

        multi_data = generate_multipart_data(register_dict)

        network_manager = getattr(qApp, "_network")

        url = SERVER_API + "register/"
        request = QNetworkRequest(QUrl(url))

        reply = network_manager.post(request, multi_data)
        reply.finished.connect(self.user_register_back)
        multi_data.setParent(reply)
Beispiel #8
0
 def get_receipt_source_file(self):
     """ 获取仓单日报数据源文件保存至本地 """
     if self.date is None:
         raise DateValueError("请先使用`set_date`设置`SHFESpider`日期.")
     url = "http://www.dce.com.cn/publicweb/quotesdata/wbillWeeklyQuotes.html"
     form_params = {
         'wbillWeeklyQuotes.variety': 'all',
         'year': str(self.date.year),
         'month': str(self.date.month - 1),
         'day': self.date.strftime("%d"),
     }
     form_data = generate_multipart_data(text_dict=form_params)
     request = QNetworkRequest(QUrl(url))
     request.setHeader(QNetworkRequest.UserAgentHeader,
                       random.choice(USER_AGENTS))
     network_manager = getattr(qApp, "_network")
     reply = network_manager.post(request, form_data)
     reply.finished.connect(self.receipt_source_file_reply)
     form_data.setParent(reply)
Beispiel #9
0
    def get_daily_source_file(self):
        """ 获取日交易源数据xls文件 """
        if self.date is None:
            raise DateValueError("请先使用`set_date`设置`DCESpider`日期.")
        url = "http://www.dce.com.cn/publicweb/quotesdata/exportDayQuotesChData.html"
        form_params = {
            "dayQuotes.variety": "all",
            "dayQuotes.trade_type": "0",
            "year": str(self.date.year),
            "month": str(self.date.month - 1),
            "day": self.date.strftime("%d"),
            "exportFlag": "excel"
        }
        form_data = generate_multipart_data(text_dict=form_params)

        network_manager = getattr(qApp, "_network")

        request = QNetworkRequest(QUrl(url))
        request.setHeader(QNetworkRequest.UserAgentHeader,
                          random.choice(USER_AGENTS))
        reply = network_manager.post(request, form_data)
        reply.finished.connect(self.daily_source_file_reply)
        form_data.setParent(reply)