Exemple #1
0
    def run(self):
        try:
            logging.info(u"【获取历史数据】线程run()中...")
            now = MyTool.getCurrentTimestamp()
            url = self.loging_success_data_dic[
                'origin_url'] + "pk/result/index?&_=%s__ajax" % now

            r1 = requests.Request(
                'GET',
                url,
                headers=self.loging_success_data_dic['headers'],
                cookies=self.loging_success_data_dic['cookies_jar'])
            prep1 = req_session.prepare_request(r1)
            rr1 = req_session.send(prep1, stream=False, timeout=10)

            # r = requests.get(url, headers=self.loging_success_data_dic['headers'],
            #                  cookies=self.loging_success_data_dic['cookies_jar'], timeout=10)

            real_content = rr1.content.split('êêê')[0]
            real_content = real_content.replace('\xef\xbb\xbf',
                                                '')  # 去掉BOM开头的\xef\xbb\xbf
            logging.info(u"【获取历史数据】结果如下")
            logging.info(real_content)

            json_data = json.loads(real_content)
            if json_data and isinstance(json_data, dict):
                QMetaObject.invokeMethod(self.console,
                                         "onUpdateHistoryResultDataHideBtn",
                                         Qt.QueuedConnection,
                                         Q_ARG(dict, json_data))
        except Exception, ex:
            logging.error(ex, exc_info=1)
Exemple #2
0
def kaijiang_xml_helper_500caipiao(my_date, play_mode=common.PLAYMODE_PK10):
    """
    500 彩票网获取开奖数据

    :param my_date:
    :param play_mode:
    :return:
    """
    import xml.dom.minidom
    import requests
    from common.common import req_session

    t_date = my_date.replace("-", "")
    if play_mode == common.PLAYMODE_PK10:
        url = common.GETDATA_URL_PK10 % t_date
    else:
        url = common.GETDATA_URL_SSC % t_date
    r = requests.Request('GET', url)

    prep = req_session.prepare_request(r)
    rr = req_session.send(prep,
                          stream=False,
                          timeout=10,
                          allow_redirects=False)
    with open(common.GETDATA_XML_PATH, 'w') as f:
        a = rr.content
        rr.close()
        dstr = a.decode('gb2312').encode('utf-8')
        dstr = dstr.replace('gb2312', 'utf-8')
        f.write(dstr)

    dom = xml.dom.minidom.parse(common.GETDATA_XML_PATH)
    root = dom.documentElement
    rows = root.getElementsByTagName("row")
    res = []
    for row in rows:
        opentime = row.getAttribute("opentime")
        if my_date not in opentime:
            continue
        qishu = row.getAttribute("expect")
        opencode = row.getAttribute("opencode")
        # 组装成["660822", "01-09 - 22:57", 7, 2, 10, 1, 9, 6, 5, 3, 4, 8, 9
        t = [str(qishu), opentime]
        t1 = opencode.split(",")
        for t2 in t1:
            t.append(int(t2))
        res.append(t)
    return res
Exemple #3
0
    def bet(self):
        if not self.all_ball_needToBetList:
            logging.error(u"【下注线程】下注列表为空,啥都不干...")
            return {-1}

        logging.info(u"【下注线程】组装下注URI..")
        # logging.info(self.console_instance.loginSuccessData)
        now = getCurrentTimestamp()
        pk_post_bet_url = self.console_instance.loginSuccessData[
            'pk_post_bet_url'].split("&&_=")[0] + "&&_=" + str(now) + "__ajax"
        logging.info(u"【下注线程】pk_post_bet_url=%s" % pk_post_bet_url)

        bet_str = self.get_bet_str(
        )  # self.console_instance.preBetDataDic['data']['integrate'])
        if not bet_str:
            logging.error(u"【下注线程】生成下注str出错!")
            logging.error(u"【下注线程】再次拿预下注数据!")
            return

        a = bet_str.split('&')

        # 如果全是0,那么就放弃算了。。。
        if a[0].split('=')[1] == 'NULL':
            return {'state': 1}

        payload = {'t': a[0].split('=')[1], 'v': int(a[1].split('=')[1])}
        logging.info("payload=%s" % payload)

        try:
            """
            如果有什么问题的话,直接让它重登算了...
            15秒下个注应该够了,如果15秒都超时,真的不如重登算了...
            """
            r1 = requests.Request(
                'POST',
                pk_post_bet_url,
                data=payload,
                headers=self.console_instance.loginSuccessData['headers'],
                cookies=self.console_instance.loginSuccessData['cookies_jar'])
            prep1 = req_session.prepare_request(r1)
            r = req_session.send(prep1,
                                 stream=False,
                                 timeout=15,
                                 allow_redirects=False)
        except Exception, ex:
            logging.error(ex, exc_info=1)
            return None
Exemple #4
0
def kaijiang_self_helper(console_instance, date, play_mode):
    """
    但是这个必须登录!!!

    自家网站的数据
    :return:
    """
    now = getCurrentTimestamp()

    if play_mode == common.PLAYMODE_PK10:
        url = console_instance.loginSuccessData[
            'origin_url'] + "pk/result/index?&_=%s__ajax" % now
    elif play_mode == common.PLAYMODE_XYFT:
        url = console_instance.loginSuccessData[
            'origin_url'] + "xyft/result/index?&_=%s__ajax" % now
    else:
        url = console_instance.loginSuccessData[
            'origin_url'] + "ssc/result/index?&_=%s__ajax" % now
    logging.info(u"获取自家网站数据,url=%s" % url)
    payload = {'date': date}
    r1 = requests.Request(
        'POST',
        url,
        data=payload,
        headers=console_instance.loginSuccessData['headers'],
        cookies=console_instance.loginSuccessData['cookies_jar'])
    prep1 = req_session.prepare_request(r1)
    rr1 = req_session.send(prep1,
                           stream=False,
                           timeout=10,
                           allow_redirects=False)
    real_content = rr1.content.split('êêê')[0]
    rr1.close()

    real_content = real_content.replace('\xef\xbb\xbf',
                                        '')  # 去掉BOM开头的\xef\xbb\xbf
    json_data = json.loads(real_content)
    if int(json_data['state']) != 1:
        logging.error(u"【获取模拟用的历史数据线程】出错!")
        logging.error(real_content)
        return []
    else:
        return json_data['data']['result']
Exemple #5
0
    def login(self):
        get_code_url1 = self.rootUrl + "/getCodeInfo/.auth?u=0.7473080656164435&systemversion=4_6&.auth"

        r1 = requests.Request('GET', get_code_url1)
        prep1 = req_session.prepare_request(r1)
        rr1 = req_session.send(prep1, stream=False, timeout=10)

        # r = requests.get(get_code_url1, timeout=10)
        a = rr1.content
        b = a.split('_')[0]
        __VerifyValue = a.split('_')[1]
        get_code_url2 = self.rootUrl + "/getVcode/.auth?t=%s&systemversion=4_6&.auth" % b

        r2 = requests.Request('GET', get_code_url2)
        prep2 = req_session.prepare_request(r2)
        rr2 = req_session.send(prep2, stream=False, timeout=10)

        # r = requests.get(get_code_url2, timeout=10)
        with open('./config/checkcode.png', 'wb') as f:
            f.write(rr2.content)

        code = self.getCheckcode()
        logging.info(u"【登录】验证码=%s" % code)
        headers = {
            'Host': self.host,
            'Proxy-Connection': 'keep-alive',
            'Accept': '*/*',
            'X-Requested-With': 'XMLHttpRequest',
            'User-Agent':
            'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.89 Safari/537.36',
            'ajax': 'true',
            'Accept-Encoding': 'gzip, deflate',
            'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
            'Origin': 'http://' + self.host,
            'Referer': self.loginUrl,
        }

        payload = {
            'VerifyCode': code,
            '__VerifyValue': __VerifyValue,
            '__name': str(self.console.userEntry.text()),
            'password': str(self.console.passEntry.text()),
            'isSec': 0,
            'cid': 1229,
            'cname': '星际',
            'systemversion': '4_6'
        }

        r3 = requests.Request('POST',
                              self.rootUrl + "/loginVerify/.auth",
                              data=payload,
                              headers=headers)
        prep3 = req_session.prepare_request(r3)
        rr3 = req_session.send(prep3, stream=False, timeout=5)

        # r = requests.post(self.rootUrl + "/loginVerify/.auth", data=payload, headers=headers, timeout=5)
        real_content = rr3.content.split('êêê')[0]
        real_content = real_content.replace('\xef\xbb\xbf',
                                            '')  # 去掉BOM开头的\xef\xbb\xbf
        a = real_content.split('\n')
        logging.info(u"【登录线程】登录body=%s" % a)
        logging.info(u"【登录线程】登录header=%s" % r3.headers)

        recheck_url = a[1].replace('host', self.host)
        cookies_jar = requests.cookies.RequestsCookieJar()
        a = rr3.headers['Set-Cookie']
        b = a.split('/,')
        ddd = "mobiLogin=0; sysinfo=ssc%7C1%7Cb%7Cuc%7Cbeishu100; navNum=0; "
        for i in b:
            if i[-6:] != 'path=/':
                i = i + '/'
            i = i[1:]
            if 'sys' in i:
                continue

            c = i.split(';')
            d = c[0].split('=')
            e = c[1].split('=')
            if '_' in e[1]:
                self.origin_url = "http://" + self.host + e[1]
            cookies_jar.set(d[0], d[1], path=e[1])
            if d[0] in ['PHPSESSID', 'AC']:
                d[1] = d[1].replace(' ', '')
                ddd += "%s=%s;" % (d[0], d[1])

        logging.info(u"【登录】cookies_jar=%s" % cookies_jar)

        headers2 = {
            'Host': 'pc10.sss66.us',
            'Proxy-Connection': 'keep-alive',
            'Upgrade-Insecure-Requests': '1',
            'User-Agent':
            'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.89 Safari/537.36',
            'Accept':
            'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
            'Referer': 'http://pc10.sss66.us/scowa1414556f/.auth',
            'Accept-Encoding': 'gzip, deflate',
            'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
        }
        self.headers = headers2
        logging.info(u"【登录线程】再次校验URL=%s" % recheck_url)

        r4 = requests.Request('GET',
                              recheck_url,
                              cookies=cookies_jar,
                              headers=headers2)
        prep4 = req_session.prepare_request(r4)
        req_session.send(prep4, stream=False, timeout=10)

        # r = requests.get(recheck_url, cookies=cookies_jar, headers=headers2, timeout=10)
        # r.close()
        return cookies_jar
Exemple #6
0
    def get_pre_bet_data(self):
        logging.info(
            "#####################start to get pre bet data...#####################"
        )
        if not self.origin_url:
            return -1
        t = ['ballNO15', 'ballNO60']
        res = []
        for i in t:
            payload = {'myaction': 'ajax', 'play': i, 'ball': '', 'cat': 15}

            r1 = requests.Request('POST',
                                  self.pk_pre_bet_get_data_url,
                                  params=payload,
                                  cookies=self.cookies_jar,
                                  headers=self.headers)
            prep1 = req_session.prepare_request(r1)
            rr1 = req_session.send(prep1, stream=False, timeout=10)

            # r = requests.post(self.pk_pre_bet_get_data_url, params=payload, cookies=self.cookies_jar,
            #                   headers=self.headers, timeout=10)
            real_content = rr1.content.split('êêê')[0]
            real_content = real_content.replace('\xef\xbb\xbf',
                                                '')  # 去掉BOM开头的\xef\xbb\xbf
            logging.info("real_content_%s =%s" % (i, real_content))

            # 当然在这里有可能遇到不想要的东西
            if "/webssc/js/plugins/ValidatorAlert" in real_content:
                # 说明应该重新登录了...
                return None
            if "window.parent.location.href =" in real_content:
                # 说明应该重新登录了...
                return None

            t_json = json.loads(real_content)
            if t_json and t_json['data']['success']:
                version_number = t_json['data']['version_number']
                win = t_json['data']['win'] if 'win' in t_json[
                    'data'] else 'NULL'
                logging.info('version_number=%s' % version_number)
                logging.info('win=%s' % win)
            else:
                version_number = -1
                logging.error("版本号拿不到咯!!!!")
                t_json = {}
            res.append(t_json)
        # 合并两个预下注数据
        pk_15_predata_json = res[0]
        pk_60_predata_json = res[1]
        try:
            if isinstance(pk_15_predata_json['data']['integrate'],
                          dict) and isinstance(
                              pk_60_predata_json['data']['integrate'], dict):
                for key, value in pk_15_predata_json['data'][
                        'integrate'].iteritems():
                    pk_60_predata_json['data']['integrate'][key] = value
            else:
                logging.info(">>>Have No integrate Data<<<")
        except Exception, ex:
            logging.error(ex, exc_info=1)
            logging.error(pk_15_predata_json['data']['integrate'])
            logging.error(type(pk_15_predata_json['data']['integrate']))
            logging.error(pk_60_predata_json['data']['integrate'])
            logging.error(type(pk_60_predata_json['data']['integrate']))
    def get_pre_bet_data(self):
        """
        要根据玩法去获取预下注数据!
        self.console_instance.play_mode = common.PLAYMODE_PK10 北京
        self.console_instance.play_mode = common.PLAYMODE_CQSSC 时时彩
        self.console_instance.play_mode = common.PLAYMODE_XYFT 幸运飞艇
        :return:
        """
        try:
            logging.info(u"【获取预下注数据线程】开始获取...")
            if not self.origin_url:
                return -1

            # 北京赛车
            if self.console_instance.play_mode in [
                    common.PLAYMODE_PK10, common.PLAYMODE_XYFT
            ]:
                t = ['ballNO15', 'ballNO60']
            # 重庆时时彩
            else:
                # 时时彩是不需要传任何参数的...
                t = ['']
            res = []
            for i in t:
                payload = {
                    'myaction': 'ajax',
                    'play': i,
                    'ball': '',
                    'cat': 15
                }

                r1 = requests.Request('POST',
                                      self.pk_pre_bet_get_data_url,
                                      params=payload,
                                      cookies=self.cookies_jar,
                                      headers=self.headers)

                prep1 = req_session.prepare_request(r1)
                rr1 = req_session.send(prep1,
                                       stream=False,
                                       timeout=10,
                                       allow_redirects=False)
                real_content = rr1.content.split('êêê')[0]
                rr1.close()
                real_content = real_content.replace('\xef\xbb\xbf',
                                                    '')  # 去掉BOM开头的\xef\xbb\xbf

                # 当然在这里有可能遇到不想要的东西
                if "/webssc/js/plugins/ValidatorAlert" in real_content:
                    logging.error(u"【获取预下注数据线程】遇到ValidatorAlert,算了重登吧...")
                    return 'RELOGIN'
                if "window.parent.location.href =" in real_content:
                    logging.error(
                        u"【获取预下注数据线程】遇到window.parent.location.href,算了重登吧...")
                    return 'RELOGIN'
                if "Request unsuccessful" in real_content:
                    logging.error(
                        u"【获取预下注数据线程】遇到Request unsuccessful,算了重登吧...")
                    return "RELOGIN"
                if len(real_content) <= 1:
                    logging.error(u"【获取预下注数据线程】JSON请求长度不大对,当做没请求过...")
                    return "NULL_DATA"

                try:
                    t_json = json.loads(real_content)
                except Exception, ex:
                    logging.error(rr1.content)
                    logging.error(real_content)
                    logging.info(u"【获取预下注数据线程】解析json数据失败...")
                    return "NULL_DATA"

                if t_json and t_json['data']['success']:
                    version_number = t_json['data']['version_number']
                    win = t_json['data']['win'] if 'win' in t_json[
                        'data'] else 'NULL'
                    logging.info('version_number=%s' % version_number)
                    logging.info('win=%s' % win)
                else:
                    version_number = -1
                    logging.error(u"【获取预下注数据线程】版本号拿不到咯!!!!")
                    t_json = {}
                res.append(t_json)

            # 如果是北京赛车合并两个预下注数据
            if self.console_instance.play_mode in [
                    common.PLAYMODE_PK10, common.PLAYMODE_XYFT
            ]:
                pk_15_predata_json = res[0]
                pk_60_predata_json = res[1]
                try:
                    if isinstance(pk_15_predata_json['data']['integrate'],
                                  dict) and isinstance(
                                      pk_60_predata_json['data']['integrate'],
                                      dict):
                        for key, value in pk_15_predata_json['data'][
                                'integrate'].iteritems():
                            pk_60_predata_json['data']['integrate'][
                                key] = value
                    else:
                        logging.info(">>>Have No integrate Data<<<")
                except Exception, ex:
                    logging.error(ex, exc_info=1)
                    logging.error(pk_15_predata_json['data']['integrate'])
                    logging.error(type(
                        pk_15_predata_json['data']['integrate']))
                    logging.error(pk_60_predata_json['data']['integrate'])
                    logging.error(type(
                        pk_60_predata_json['data']['integrate']))
                return pk_60_predata_json