Ver Fonte

wq,bq,roll_wq,lq

unknown há 6 anos atrás
pai
commit
de0cebac68
32 ficheiros alterados com 1306 adições e 313 exclusões
  1. BIN
      hg3535/__pycache__/__init__.cpython-36.pyc
  2. BIN
      hg3535/__pycache__/items.cpython-36.pyc
  3. BIN
      hg3535/__pycache__/middlewares.cpython-36.pyc
  4. BIN
      hg3535/__pycache__/settings.cpython-36.pyc
  5. 6 0
      hg3535/items.py
  6. 2 2
      hg3535/main.py
  7. 342 0
      hg3535/pipeline/bangqiu.py
  8. 124 144
      hg3535/pipeline/lanqiu.py
  9. 294 0
      hg3535/pipeline/roll_wangqiu.py
  10. 315 0
      hg3535/pipeline/wangqiu.py
  11. 1 1
      hg3535/pipeline/zuqiu.py
  12. BIN
      hg3535/spiders/__pycache__/__init__.cpython-36.pyc
  13. BIN
      hg3535/spiders/__pycache__/bangqiu.cpython-36.pyc
  14. BIN
      hg3535/spiders/__pycache__/bq_jieshu.cpython-36.pyc
  15. BIN
      hg3535/spiders/__pycache__/guanjun.cpython-36.pyc
  16. BIN
      hg3535/spiders/__pycache__/lanqiu.cpython-36.pyc
  17. BIN
      hg3535/spiders/__pycache__/liansai.cpython-36.pyc
  18. BIN
      hg3535/spiders/__pycache__/lq_jieshu.cpython-36.pyc
  19. BIN
      hg3535/spiders/__pycache__/roll_bangqiu.cpython-36.pyc
  20. BIN
      hg3535/spiders/__pycache__/roll_lanqiu.cpython-36.pyc
  21. BIN
      hg3535/spiders/__pycache__/roll_wangqiu.cpython-36.pyc
  22. BIN
      hg3535/spiders/__pycache__/roll_zuqiu.cpython-36.pyc
  23. BIN
      hg3535/spiders/__pycache__/wangqiu.cpython-36.pyc
  24. BIN
      hg3535/spiders/__pycache__/wq_jieshu.cpython-36.pyc
  25. BIN
      hg3535/spiders/__pycache__/wqbodan.cpython-36.pyc
  26. BIN
      hg3535/spiders/__pycache__/zq_jieshu.cpython-36.pyc
  27. BIN
      hg3535/spiders/__pycache__/zuqiu.cpython-36.pyc
  28. 68 17
      hg3535/spiders/bangqiu.py
  29. 64 52
      hg3535/spiders/lanqiu.py
  30. 2 2
      hg3535/spiders/roll_bangqiu.py
  31. 50 53
      hg3535/spiders/roll_wangqiu.py
  32. 38 42
      hg3535/spiders/wangqiu.py

BIN
hg3535/__pycache__/__init__.cpython-36.pyc


BIN
hg3535/__pycache__/items.cpython-36.pyc


BIN
hg3535/__pycache__/middlewares.cpython-36.pyc


BIN
hg3535/__pycache__/settings.cpython-36.pyc


+ 6 - 0
hg3535/items.py

@@ -252,6 +252,10 @@ class Bangqiu(scrapy.Field):
     total_size_dict_rule = scrapy.Field()
     odd_evens_dict = scrapy.Field()
     odd_evens_dict_rule = scrapy.Field()
+    team_score_home_dict = scrapy.Field()
+    team_score_home_rule_dict = scrapy.Field()
+    team_score_guest_dict = scrapy.Field()
+    team_score_guest_rule_dict = scrapy.Field()
     bangqiu = scrapy.Field()
 
 
@@ -396,6 +400,8 @@ class Roll_Wangqiu(scrapy.Field):
     jijie = scrapy.Field()
     # 球队得分
     qiudui = scrapy.Field()
+    # 每局比分
+    score_dict = scrapy.Field()
     pt = scrapy.Field()
 
     concedes_dict = scrapy.Field()

+ 2 - 2
hg3535/main.py

@@ -7,13 +7,13 @@ sys.path.append(os.path.dirname(os.path.abspath(__file__)))
 # execute(["scrapy", "crawl", "liansai"])
 # execute(["scrapy", "crawl", "zuqiu"])
 # execute(["scrapy", "crawl", "lanqiu"])
-execute(["scrapy", "crawl", "guanjun"])
+# execute(["scrapy", "crawl", "guanjun"])
 # execute(["scrapy", "crawl", "wangqiu"])
 # execute(["scrapy", "crawl", "wqbodan"])
 # execute(["scrapy", "crawl", "bangqiu"])
 # execute(["scrapy", "crawl", "roll_zuqiu"]) #滚球足球 回来要解开这个注释 其他全部解封
 # execute(["scrapy", "crawl", "roll_lanqiu"]) #滚球篮球
-# execute(["scrapy", "crawl", "roll_wangqiu"]) #滚球网球
+execute(["scrapy", "crawl", "roll_wangqiu"]) #滚球网球
 # execute(["scrapy", "crawl", "roll_bangqiu"]) #滚球棒球
 # execute(["scrapy", "crawl", "ball_status"]) #滚球id本地存
 # execute(["scrapy", "crawl", "ball_status_update"]) #滚球id结束时间更新状态

+ 342 - 0
hg3535/pipeline/bangqiu.py

@@ -0,0 +1,342 @@
+import datetime
+import pymongo
+import time
+import logging
+from .ball_func import fuhao
+from ..utils.helper import Helper
+from .ball_func import get_pcode, new_time, out_time
+from concurrent.futures import ThreadPoolExecutor
+from requests_futures.sessions import FuturesSession
+
+
+class Bangqiupipeline(object):
+    def open_spider(self, spider):
+        self.mongo = pymongo.MongoClient(host="192.168.2.200", username="kaiyou", password="kaiyou", port=27017)
+        self.db = self.mongo['kaiyou']
+        self.session = FuturesSession(executor=ThreadPoolExecutor(max_workers=10))
+
+    def process_item(self, item, spider):
+        # print(item)
+        logger = logging.getLogger(__name__)
+        url = 'http://admin.5gogo.com'
+        # logger.warning(query.addErrback(self.handle_error, item, spider))
+        # 联赛id
+        league_id = item['league_id']
+        # 联赛名
+        league_name = item['league_name']
+        # result = item['result']
+        # 比赛id
+        match_id = item['game_id']
+        # 球队1
+        team_home = item['team_home']
+        # 球队2
+        team_guest = item['team_guest']
+        # 数量(97>)
+        tag_number = item['number']
+        # 比赛状态
+        zhuangtai = item['zhuangtai']
+        # 日期
+        # data_game = item['data_game']
+        try:
+            data_game = item['data_game'].split("/")
+            month = str(data_game[1].strip())
+            day = str(data_game[0])
+        except Exception as e:
+            # logger.warning('data_game字段分割错误')
+            # logger.warning(e)
+            data_game = item['data_game'].split(" ")
+            months = str(data_game[1].strip())
+            month_dict = {'Jan': '01', 'Feb': '02', 'Mar': '03', 'Apr': '04', 'May': '05', 'Jun': '06', 'Jul': '07',
+                          'Aug': '08', 'Sep': '09', 'Oct': '10', 'Nov': '11', 'Dec': '12'}
+            month = month_dict[months]
+            day = str(data_game[0])
+        # 比赛时间
+        time_game = str(item['time_game'])
+        # 比赛时间,时间戳
+        ctime = "2019" + "-" + month + "-" + day + " " + time_game + ":00"
+        r_ctime = "2019" + "-" + month + "-" + day
+        # 现在时间,时间戳
+        utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
+        expire_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() + 60))
+        # 队1分数
+        score_home = item['score_home']
+        # 队2分数
+        score_guest = item['score_guest']
+        # 第几节
+        jijie = item['jijie']
+        # 球队得分
+        qiudui = item['qiudui']
+        pt = item['pt']
+        # 让球
+        concedes_dict = item['concedes_dict']
+        concedes_dict_rule = item['concedes_dict_rule']
+        # 独赢
+        capots_dict = item['capots_dict']
+        # 总得分大小
+        total_size_dict = item['total_size_dict']
+        total_size_dict_rule = item['total_size_dict_rule']
+        # 总得分单双
+        odd_evens_dict = item['odd_evens_dict']
+        odd_evens_dict_rule = item['odd_evens_dict_rule']
+        # 球队得分 主队
+        try:
+            team_score_home_dict = item['team_score_home_dict']
+            team_score_home_rule_dict = item['team_score_home_rule_dict']
+        except:
+            team_score_home_dict = ""
+            team_score_home_rule_dict = ""
+        # 球队得分 客队
+        try:
+            team_score_guest_dict = item['team_score_guest_dict']
+            team_score_guest_rule_dict = item['team_score_guest_rule_dict']
+        except:
+            team_score_guest_dict = ""
+            team_score_guest_rule_dict = ""
+        bangqiu = item['bangqiu']
+        match_date, match_time, time3 = new_time(ctime)
+        us_time = ctime
+        uuid = Helper.genearte_MD5(league_name + 'hg3535')
+        """联赛表"""
+        last_time = '2019-12-31 23:59:59'
+        league_dict = {"game_code": "bq", "title": "league", "source": "hg3535"}
+        league_list = []
+
+        league_key = ["name_chinese", "kind", "match_mode", "if_stop", "last_time", "lg_id", "source", "uuid"]
+        league_value = [league_name, "1", "1", "0", last_time, league_id, "hg3535", uuid]
+        league_data = dict(zip(league_key, league_value))
+        league_list.append(league_data)
+        league_dict['data'] = league_list
+        # print(league_list)
+        # print(league_dict)
+        if self.db.hg3535_bq_league.find({'lg_id': league_id}).count() < 1:
+            res = Helper.async_post(url + '/setLeague', league_dict)
+            print(res)
+            self.db.hg3535_bq_league.insert(league_list)
+
+        """插入赛事表"""
+        competition = self.db.hg3535_bq_competition.find_one({"match_id": str(match_id)})
+        match_list = []
+        if competition:
+            print('赛事已存在,修改赛事四状态')
+            is_morningplate = competition['is_morningplate']
+            is_rollball = competition['is_rollball']
+            is_stringscene = competition['is_stringscene']
+            is_today = competition['is_today']
+            lmtime = competition['match_time']
+            if pt == 3:
+                if is_stringscene != 1 or lmtime != match_time:
+                    match_dict = {"game_code": "bq", "title": "match", "source": "hg3535"}
+                    match_key = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
+                                 "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
+                                 "half_match_id", "is_today"]
+                    match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number,
+                                   "hg3535", is_rollball, is_morningplate, 1, us_time, uuid, 0, is_today]
+                    match_data = dict(zip(match_key, match_value))
+                    match_list.append(match_data)
+                    match_dict['data'] = match_list
+                    # print(match_list)
+                    # print(match_dict)
+                    res = Helper.async_post(url + '/setMatch', match_dict)
+                    print(res)
+                    self.db.hg3535_bq_competition.update({'match_id': match_id},
+                                                         {"$set": {"is_stringscene": 1, 'match_time': match_time}},
+                                                         upsert=True)
+            if pt == 2:
+                if is_morningplate != 1 or lmtime != match_time:
+                    match_dict = {"game_code": "bq", "title": "match", "source": "hg3535"}
+                    match_key = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
+                                 "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
+                                 "half_match_id", "is_today"]
+                    match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number,
+                                   "hg3535", is_rollball, 1, is_stringscene, us_time, uuid, 0, is_today]
+                    match_data = dict(zip(match_key, match_value))
+                    match_list.append(match_data)
+                    match_dict['data'] = match_list
+                    # print(match_list)
+                    # print(match_dict)
+                    res = Helper.async_post(url + '/setMatch', match_dict)
+                    print(res)
+                    self.db.hg3535_bq_competition.update({'match_id': match_id},
+                                                         {"$set": {"is_morningplate": 1, 'match_time': match_time}},
+                                                         upsert=True)
+            if pt == 1:
+                if is_today != 1 or lmtime != match_time:
+                    match_dict = {"game_code": "bq", "title": "match", "source": "hg3535"}
+                    match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
+                                 "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
+                                 "half_match_id", "is_today"]
+                    match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number,
+                                   "hg3535", is_rollball, is_morningplate, is_stringscene, us_time, uuid, 0, 1]
+                    match_data = dict(zip(match_kay, match_value))
+                    match_list.append(match_data)
+                    match_dict['data'] = match_list
+                    # print(match_list)
+                    # print(match_dict)
+                    res = Helper.async_post(url + '/setMatch', match_dict)
+                    print(res)
+                    self.db.hg3535_bq_competition.update({'match_id': match_id},
+                                                         {"$set": {"is_today": 1, 'match_time': match_time}},
+                                                         upsert=True)
+            else:
+                print("赛事已存在,赛事状态时间未改变,不做修改")
+        else:
+            print('赛事不存在, 插入新数据')
+            if pt == 3:
+                is_rollball = 0
+                is_today = 0
+                is_morningplate = 0
+                is_stringscene = 1
+            elif pt == 2:
+                is_rollball = 0
+                is_today = 0
+                is_morningplate = 1
+                is_stringscene = 0
+            else:
+                is_today = 1
+                is_rollball = 0
+                is_morningplate = 0
+                is_stringscene = 0
+            match_dict = {"game_code": "bq", "title": "match", "source": "hg3535"}
+            match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time", "tag",
+                         "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
+                         "half_match_id", "is_today"]
+            match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number, "hg3535",
+                           is_rollball, is_morningplate, is_stringscene, us_time, uuid, 0, is_today]
+            match_data = dict(zip(match_kay, match_value))
+            match_list.append(match_data)
+            match_dict['data'] = match_list
+            res = Helper.async_post(url + '/setMatch', match_dict)
+            print(res)
+            self.db.hg3535_bq_competition.insert(match_list)
+
+        """赔率"""
+        try:
+            result = self.db.hg3535_bq_odds.find_one({'match_id': str(match_id), 'pt': pt})
+            odds_only_list = result['odds_only']
+        except:
+            result = ''
+            odds_only_list = []
+        data_list = []
+        odds_onlys = []
+        # 让球
+        if concedes_dict:
+            for key, value in concedes_dict.items():
+                sole_str = 'concede' + str(key) + str(match_id) + 'hg3535'
+                sole = Helper.genearte_MD5(sole_str)
+                odds_str = 'concede' + str(key) + str(match_id) + 'hg3535' + str(concedes_dict_rule[key]) + str(
+                    value)
+                odds_only = Helper.genearte_MD5(odds_str)
+                condition = fuhao(str(concedes_dict_rule[key]))
+                concedes_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
+                                     "odds_only", "sole", "source", "type", "team"]
+                concedes_dict_value = [match_id, league_id, key, '0', '0', 'concede', value, condition,
+                                       odds_only, sole, 'hg3535', '0', '']
+                concedes_dict_data = dict(zip(concedes_dict_key, concedes_dict_value))
+                odds_onlys.append(odds_only)
+                if odds_only not in odds_only_list:
+                    data_list.append(concedes_dict_data)
+        # 总得分大/小
+        if total_size_dict:
+            for key, value in total_size_dict.items():
+                sole_str = 'total_size' + str(key) + str(match_id) + 'hg3535'
+                sole = Helper.genearte_MD5(sole_str)
+                odds_str = 'total_size' + str(key) + str(match_id) + 'hg3535' + str(
+                    total_size_dict_rule[key]) + str(value)
+                odds_only = Helper.genearte_MD5(odds_str)
+                condition = fuhao(str(total_size_dict_rule[key]))
+                total_size_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
+                                       "condition", "odds_only", "sole", "source", "type", "team"]
+                total_size_dict_value = [match_id, league_id, key, '0', '0', 'total_size', value, condition,
+                                         odds_only, sole, 'hg3535', '0', '']
+                total_size_dict_data = dict(zip(total_size_dict_key, total_size_dict_value))
+                odds_onlys.append(odds_only)
+                if odds_only not in odds_only_list:
+                    data_list.append(total_size_dict_data)
+        # 球队得分大/小 主队
+        if team_score_home_dict:
+            for key, value in team_score_home_dict.items():
+                sole_str = 'team_score_home' + str(key) + str(match_id) + 'hg3535'
+                sole = Helper.genearte_MD5(sole_str)
+                odds_str = 'team_score_home' + str(key) + str(match_id) + 'hg3535' + str(
+                    team_score_home_rule_dict[key]) + str(value)
+                odds_only = Helper.genearte_MD5(odds_str)
+                condition = fuhao(str(team_score_home_rule_dict[key]))
+                team_score_home_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
+                                            "condition", "odds_only", "sole", "source", "type", "team"]
+                team_score_home_dict_value = [match_id, league_id, key, '0', '0', 'team_score_home', value, condition,
+                                              odds_only, sole, 'hg3535', '0', '']
+                team_score_home_dict_data = dict(zip(team_score_home_dict_key, team_score_home_dict_value))
+                odds_onlys.append(odds_only)
+                if odds_only not in odds_only_list:
+                    data_list.append(team_score_home_dict_data)
+        # 球队得分大/小 客队
+        if team_score_guest_dict:
+            for key, value in team_score_guest_dict.items():
+                sole_str = 'team_score_guest' + str(key) + str(match_id) + 'hg3535'
+                sole = Helper.genearte_MD5(sole_str)
+                odds_str = 'team_score_guest' + str(key) + str(match_id) + 'hg3535' + str(
+                    team_score_guest_rule_dict[key]) + str(value)
+                odds_only = Helper.genearte_MD5(odds_str)
+                condition = fuhao(str(team_score_guest_rule_dict[key]))
+                team_score_guest_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
+                                             "condition", "odds_only", "sole", "source", "type", "team"]
+                team_score_guest_dict_value = [match_id, league_id, key, '0', '0', 'team_score_guest', value, condition,
+                                               odds_only, sole, 'hg3535', '0', '']
+                team_score_guest_dict_data = dict(zip(team_score_guest_dict_key, team_score_guest_dict_value))
+                odds_onlys.append(odds_only)
+                if odds_only not in odds_only_list:
+                    data_list.append(team_score_guest_dict_data)
+        # 独赢
+        if capots_dict:
+            for key, value in capots_dict.items():
+                sole_str = 'capot' + str(key) + str(match_id) + 'hg3535'
+                sole = Helper.genearte_MD5(sole_str)
+                odds_str = 'capot' + str(key) + str(match_id) + 'hg3535' + str(value)
+                odds_only = Helper.genearte_MD5(odds_str)
+                capots_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
+                                   "condition", "odds_only", "sole", "source", "type", "team"]
+                capots_dict_value = [match_id, league_id, key, '0', '0', 'capot', value, '',
+                                     odds_only, sole, 'hg3535', '0', '']
+                capots_dict_data = dict(zip(capots_dict_key, capots_dict_value))
+                odds_onlys.append(odds_only)
+                if odds_only not in odds_only_list:
+                    data_list.append(capots_dict_data)
+        # 总得分单双
+        if odd_evens_dict:
+            for key, value in odd_evens_dict.items():
+                sole_str = 'two_sides' + str(key) + str(match_id) + 'hg3535'
+                sole = Helper.genearte_MD5(sole_str)
+                odds_str = 'two_sides' + str(key) + str(match_id) + 'hg3535' + str(
+                    odd_evens_dict_rule[key]) + str(value)
+                odds_only = Helper.genearte_MD5(odds_str)
+                condition = fuhao(str(odd_evens_dict_rule[key]))
+                odd_evens_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
+                                      "condition", "odds_only", "sole", "source", "type", "team"]
+                odd_evens_dict_value = [match_id, league_id, key, '0', '0', 'two_sides', value, condition,
+                                        odds_only, sole, 'hg3535', '0', '']
+                odd_evens_dict_data = dict(zip(odd_evens_dict_key, odd_evens_dict_value))
+                odds_onlys.append(odds_only)
+                if odds_only not in odds_only_list:
+                    data_list.append(odd_evens_dict_data)
+        # 让球 前五局
+        # 总得分大/小 前五局
+        if pt == 3:
+            ris_stringscene = 1
+        else:
+            ris_stringscene = 0
+        odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid",
+                    "is_stringscene", "utime", "pt"]
+        odds_value = ["bq", "odds", match_id, league_id, data_list, "hg3535", odds_onlys, tag_number, uuid,
+                      ris_stringscene, utime, pt]
+        odds_dict = dict(zip(odds_key, odds_value))
+        # print(odds_dict)
+        # print(123)
+        if data_list:
+            res = Helper.async_post(url + '/setOdds', odds_dict)
+            print(res)
+            if '成功' in res:
+                if result:
+                    self.db.hg3535_bq_odds.update({'match_id': match_id, 'pt': pt}, {
+                        '$set': {"data": data_list, "odds_only": odds_onlys, "utime": utime}}, upsert=True)
+                else:
+                    self.db.hg3535_bq_odds.insert(odds_dict)

+ 124 - 144
hg3535/pipeline/lanqiu.py

@@ -1,16 +1,23 @@
-# import datetime
-# import json
-# import pymongo
+import datetime
+import json
+import pymongo
 import time
 import logging
-# import requests
+import requests
+from .ball_func import fuhao
 
-# from ball_func import fuhao
 from ..utils.helper import Helper
 from .ball_func import get_pcode, new_time, out_time
+from concurrent.futures import ThreadPoolExecutor
+from requests_futures.sessions import FuturesSession
 
 
 class Lanqiupipeline(object):
+    def open_spider(self, spider):
+        self.mongo = pymongo.MongoClient(host="192.168.2.200", username="kaiyou", password="kaiyou", port=27017)
+        self.db = self.mongo['kaiyou']
+        self.session = FuturesSession(executor=ThreadPoolExecutor(max_workers=10))
+
     def process_item(self, item, spider):
         # 使用twisted将mysql插入变成异步执行
         lq_odds = []
@@ -76,144 +83,117 @@ class Lanqiupipeline(object):
         # 让球
         lanqiu = item['lanqiu']
         match_date, match_time, time3 = new_time(us_time)
-        # 让球 数据插入数据库
-        last_time = '2019-12-31 23:59:59'
-        league_dict = {"game_code": "lq", "title": "league", "source": "hg3535"}
-        league_list = []
         uuid = Helper.genearte_MD5(league_name + 'hg3535')
-        league_key = ["name_chinese", "kind", "match_mode", "if_stop", "last_time", "lg_id", "source", "uuid"]
-        league_value = [league_name, "1", "1", "0", last_time, league_id, "hg3535", uuid]
-        league_data = dict(zip(league_key, league_value))
-        league_list.append(league_data)
-        league_dict['data'] = league_list
-        response_data = Helper.async_post(url + '/setLeague', league_dict)
-        print(response_data)
-        if pt == '3':
-            is_rollball = 0
-            is_today = 0
-            is_morningplate = 0
-            is_stringscene = 1
-        elif pt == '2':
-            is_rollball = 0
-            is_today = 0
-            is_morningplate = 1
-            is_stringscene = 0
-        else:
-            is_today = 1
-            is_rollball = 0
-            is_morningplate = 0
-            is_stringscene = 0
-        # 赛事接口写入
-        match_dict = {"game_code": "lq", "title": "match", "source": "hg3535"}
-        match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time", "tag",
-                     "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid", "half_match_id", "is_today"]
-        match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number, "hg3535",
-                       is_rollball, is_morningplate, is_stringscene, us_time, uuid, 0, is_today]
-        match_list = []
-        match_data = dict(zip(match_kay, match_value))
-        match_list.append(match_data)
-        match_dict['data'] = match_list
-        response_data = Helper.async_post(url + '/setMatch', match_dict)
-        print(response_data)
+        # 让球 数据插入数据库
+        """联赛"""
+        # last_time = '2019-12-31 23:59:59'
+        # league_dict = {"game_code": "lq", "title": "league", "source": "hg3535"}
+        # league_list = []
+
+        # league_key = ["name_chinese", "kind", "match_mode", "if_stop", "last_time", "lg_id", "source", "uuid"]
+        # league_value = [league_name, "1", "1", "0", last_time, league_id, "hg3535", uuid]
+        # league_data = dict(zip(league_key, league_value))
+        # league_list.append(league_data)
+        # league_dict['data'] = league_list
+        # # print(league_list)
+        # # print(league_dict)
+        # if self.db.hg3535_lq_league.find({'lg_id': league_id}).count() < 1:
+        #     res = Helper.async_post(url + '/setLeague', league_dict)
+        #     print(res)
+        #     self.db.hg3535_lq_league.insert(league_list)
 
-        # if concedes_dict:
-        #     for key, value in concedes_dict.items():
-        #         two_post(data=value, match_id=game_id, odds_code=key, p_id=1,
-        #                  league_id=league_id, p_code='concede', condition=concedes_dict_rule[key], game_code='lq', zq_odds=lq_odds)
-        # if odd_evens_dict:
-        #     for key, value in odd_evens_dict.items():
-        #         one_post(data=value, match_id=game_id, odds_code=key, p_id=2,
-        #                  league_id=league_id, p_code='two_sides', condition=odd_evens_dict_rule[key], game_code='lq', zq_odds=lq_odds)
-        # # 总分单双 数据插入数据库
-        # if total_sizes_dict:
-        #     for key, value in total_sizes_dict.items():
-        #         two_post(data=value, match_id=game_id, odds_code=key, p_id=3,
-        #                  league_id=league_id, p_code='total_size', condition=total_sizes_dict_rule[key], game_code='lq', zq_odds=lq_odds)
-        # # 全场总分大小 数据插入数据库
-        # # 全场总分大小 数据插入数据库
-        # if team_scores_dict:
-        #     for key, value in team_scores_dict.items():
-        #         two_post(data=value, match_id=game_id, odds_code=key, p_id=6,
-        #                  league_id=league_id, p_code='total_size', condition=team_scores_dict_rule[key], game_code='lq', zq_odds=lq_odds)
-        # lastnumber_dict = {'0或5': '_zero_five', '1或6': '_one_six', '2或7': '_two_seven', '3或8': '_three_eight', '4或9': '_four_nine'}
-        # if last_numbers_dict['last_home']:
-        #     for key, value in last_numbers_dict['last_home'].items():
-        #         one_post(data=value, match_id=game_id, odds_code="last_home" + lastnumber_dict[key], p_id=4,
-        #                  league_id=league_id, p_code='last_number', condition=key, game_code='lq', zq_odds=lq_odds)
-        # if last_numbers_dict['last_guest']:
-        #     for key, value in last_numbers_dict['last_guest'].items():
-        #         one_post(data=value, match_id=game_id, odds_code="last_guest" + lastnumber_dict[key], p_id=4,
-        #                  league_id=league_id, p_code='last_number', condition=key, game_code='lq', zq_odds=lq_odds)
-        # three_post(data=capots_dict, match_id=game_id, p_id=5, league_id=league_id, p_code='capot', condition="", game_code='lq', zq_odds=lq_odds)
-        # match_date, match_time, time3 = new_time(ctime)
-        # n_time = out_time(time3, 1.5)
-        # us_time = ctime
-        # if lanqiu == "篮球":
-        #     if pt == 1:
-        #         payload = {
-        #             "game_code": "lq",
-        #             "title": "competition",
-        #             "data": {
-        #                 "home_team": team_home,
-        #                 "guest_team": team_guest,
-        #                 "lg_id": league_id,
-        #                 "status": 0,
-        #                 "match_id": game_id,
-        #                 "match_date": match_date,
-        #                 "match_time": match_time,
-        #                 "tag": number,
-        #                 "source": "hg3535",
-        #                 "is_rollball": 0,
-        #                 "is_today": 1,
-        #                 "is_morningplate": 0,
-        #                 "is_stringscene": 0,
-        #                 "us_time": us_time
-        #             }
-        #         }
-        #     if pt == 2:
-        #         payload = {
-        #             "game_code": "lq",
-        #             "title": "competition",
-        #             "data": {
-        #                 "home_team": team_home,
-        #                 "guest_team": team_guest,
-        #                 "lg_id": league_id,
-        #                 "status": 0,
-        #                 "match_id": game_id,
-        #                 "match_date": match_date,
-        #                 "match_time": match_time,
-        #                 "tag": number,
-        #                 "source": "hg3535",
-        #                 "is_rollball": 0,
-        #                 "is_today": 0,
-        #                 "is_morningplate": 1,
-        #                 "is_stringscene": 0,
-        #                 "us_time": us_time
-        #             }
-        #         }
-        #     if pt == 3:
-        #         payload = {
-        #             "game_code": "lq",
-        #             "title": "competition",
-        #             "data": {
-        #                 "home_team": team_home,
-        #                 "guest_team": team_guest,
-        #                 "lg_id": league_id,
-        #                 "status": 0,
-        #                 "match_id": game_id,
-        #                 "match_date": match_date,
-        #                 "match_time": match_time,
-        #                 "tag": number,
-        #                 "source": "hg3535",
-        #                 "is_rollball": 0,
-        #                 "is_today": 0,
-        #                 "is_morningplate": 0,
-        #                 "is_stringscene": 1,
-        #                 "us_time": us_time
-        #             }
-        #         }
-        #     lq_odds.insert(0, payload)
-        # r = requests.post(url, data={"data": json.dumps(lq_odds)})
-        # # logger.warning(r.text)
-        # print(r.text)
-        # return item
+        """赛事"""
+        competition = self.db.hg3535_lq_competition.find_one({"match_id": str(match_id)})
+        match_list = []
+        if competition:
+            print('赛事已存在,修改赛事四状态')
+            is_morningplate = competition['is_morningplate']
+            is_rollball = competition['is_rollball']
+            is_stringscene = competition['is_stringscene']
+            is_today = competition['is_today']
+            lmtime = competition['match_time']
+            if pt == 3:
+                if is_stringscene != 1 or lmtime != match_time:
+                    match_dict = {"game_code": "lq", "title": "match", "source": "hg3535"}
+                    match_key = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
+                                 "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
+                                 "half_match_id", "is_today", 'pt']
+                    match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number,
+                                   "hg3535", is_rollball, is_morningplate, 1, us_time, uuid, 0, is_today, pt]
+                    match_data = dict(zip(match_key, match_value))
+                    match_list.append(match_data)
+                    match_dict['data'] = match_list
+                    # print(match_list)
+                    # print(match_dict)
+                    res = Helper.async_post(url + '/setMatch', match_dict)
+                    print(res)
+                    self.db.hg3535_lq_competition.update({'match_id': str(match_id)},
+                                                         {"$set": {"is_stringscene": 1, 'match_time': match_time}},
+                                                         upsert=True)
+            if pt == 2:
+                if is_morningplate != 1 or lmtime != match_time:
+                    match_dict = {"game_code": "lq", "title": "match", "source": "hg3535"}
+                    match_key = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
+                                 "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
+                                 "half_match_id", "is_today", 'pt']
+                    match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number,
+                                   "hg3535", is_rollball, 1, is_stringscene, us_time, uuid, 0, is_today, pt]
+                    match_data = dict(zip(match_key, match_value))
+                    match_list.append(match_data)
+                    match_dict['data'] = match_list
+                    # print(match_list)
+                    # print(match_dict)
+                    res = Helper.async_post(url + '/setMatch', match_dict)
+                    print(res)
+                    self.db.hg3535_lq_competition.update({'match_id': str(match_id)},
+                                                         {"$set": {"is_morningplate": 1, 'match_time': match_time}},
+                                                         upsert=True)
+            if pt == 1:
+                if is_today != 1 or lmtime != match_time:
+                    match_dict = {"game_code": "lq", "title": "match", "source": "hg3535"}
+                    match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
+                                 "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
+                                 "half_match_id", "is_today", 'pt']
+                    match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number,
+                                   "hg3535", is_rollball, is_morningplate, is_stringscene, us_time, uuid, 0, 1, pt]
+                    match_data = dict(zip(match_kay, match_value))
+                    match_list.append(match_data)
+                    match_dict['data'] = match_list
+                    # print(match_list)
+                    # print(match_dict)
+                    res = Helper.async_post(url + '/setMatch', match_dict)
+                    print(res)
+                    self.db.hg3535_lq_competition.update({'match_id': str(match_id)},
+                                                         {"$set": {"is_today": 1, 'match_time': match_time}},
+                                                         upsert=True)
+            else:
+                print("赛事已存在,赛事状态时间未改变,不做修改")
+        else:
+            print('赛事不存在,插入新赛事')
+            if pt == 3:
+                is_rollball = 0
+                is_today = 0
+                is_morningplate = 0
+                is_stringscene = 1
+            elif pt == 2:
+                is_rollball = 0
+                is_today = 0
+                is_morningplate = 1
+                is_stringscene = 0
+            else:
+                is_today = 1
+                is_rollball = 0
+                is_morningplate = 0
+                is_stringscene = 0
+            match_dict = {"game_code": "lq", "title": "match", "source": "hg3535"}
+            match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time", "tag",
+                         "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
+                         "half_match_id", "is_today", 'pt']
+            match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number, "hg3535",
+                           is_rollball, is_morningplate, is_stringscene, us_time, uuid, 0, is_today, pt]
+            match_data = dict(zip(match_kay, match_value))
+            match_list.append(match_data)
+            match_dict['data'] = match_list
+            res = Helper.async_post(url + '/setMatch', match_dict)
+            print(res)
+            self.db.hg3535_lq_competition.insert(match_list)

+ 294 - 0
hg3535/pipeline/roll_wangqiu.py

@@ -0,0 +1,294 @@
+import datetime
+import pymongo
+import time
+import logging
+import json
+from .ball_func import fuhao
+from ..utils.helper import Helper
+from .ball_func import get_pcode, new_time, out_time
+from concurrent.futures import ThreadPoolExecutor
+from requests_futures.sessions import FuturesSession
+
+
+class Roll_Wangqiupipeline(object):
+    def open_spider(self, spider):
+        self.mongo = pymongo.MongoClient(host="192.168.2.200", username="kaiyou", password="kaiyou", port=27017)
+        self.db = self.mongo['kaiyou']
+        self.session = FuturesSession(executor=ThreadPoolExecutor(max_workers=10))
+
+    def process_item(self, item, spider):
+        url = 'http://admin.5gogo.com'
+        logger = logging.getLogger(__name__)
+        # 联赛id
+        league_id = item['league_id']
+        # 联赛名
+        league_name = item['league_name']
+        # result = item['result']
+        # 比赛id
+        match_id = item['game_id']
+        # 球队1
+        team_home = item['team_home']
+        # 球队2
+        team_guest = item['team_guest']
+        # 数量(97>)
+        tag_number = item['number']
+        # 比赛状态
+        zhuangtai = item['zhuangtai']
+        # 日期
+        # data_game = item['data_game']
+        try:
+            data_game = item['data_game'].split("/")
+            month = str(data_game[1].strip())
+            day = str(data_game[0])
+        except Exception as e:
+            logger.warning(e)
+            data_game = item['data_game'].split(" ")
+            months = str(data_game[1].strip())
+            month_dict = {'Jan': '01', 'Feb': '02', 'Mar': '03', 'Apr': '04', 'May': '05', 'Jun': '06', 'Jul': '07',
+                          'Aug': '08', 'Sep': '09', 'Oct': '10', 'Nov': '11', 'Dec': '12'}
+            month = month_dict[months]
+            day = str(data_game[0])
+        # 比赛时间
+        time_game = str(item['time_game'])
+        # 比赛时间,时间戳
+        ctime = "2019" + "-" + month + "-" + day + "" + time_game + ":00"
+        r_ctime = "2019" + "-" + month + "-" + day
+        # 现在时间,时间戳
+        utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
+        # 队1分数
+        score_home = item['score_home']
+        # 队2分数
+        score_guest = item['score_guest']
+        # 第几节
+        jijie = item['jijie']
+        # 球队得分
+        qiudui = item['qiudui']
+        pt = 4
+        # 取不到 暂时注掉
+        # match_date, match_time = new_times(ctime)
+        # 每局比分
+        score_dict = item['score_dict']
+        # 让盘
+        concedes_dict = item['concedes_dict']
+        concedes_dict_rule = item['concedes_dict_rule']
+        # 冠军 独赢
+        kemps_dict = item['kemps_dict']
+        # 让局
+        bureaus_dict = item['bureaus_dict']
+        bureaus_dict_rule = item['bureaus_dict_rule']
+        # 总局数大小
+        total_number_dict = item['total_number_dict']
+        total_number_dict_rule = item['total_number_dict_rule']
+        # 总局数单双
+        odd_evens_dict = item['odd_evens_dict']
+        odd_evens_dict_rule = item['odd_evens_dict_rule']
+        sq_dict = item['sq_dict']
+        new_sq_dict = json.dumps(sq_dict)
+        uuid = Helper.genearte_MD5(league_name + 'hg3535')
+        """联赛"""
+        # last_time = '2019-12-31 23:59:59'
+        # league_dict = {"game_code": "wq", "title": "league", "source": "hg3535"}
+        # league_list = []
+        #
+        # league_key = ["name_chinese", "kind", "match_mode", "if_stop", "last_time", "lg_id", "source", "uuid"]
+        # league_value = [league_name, "1", "1", "0", last_time, league_id, "hg3535", uuid]
+        # league_data = dict(zip(league_key, league_value))
+        # league_list.append(league_data)
+        # league_dict['data'] = league_list
+        # if self.db.hg3535_wq_league.find({'lg_id': league_id}).count() < 1:
+        #     res = Helper.async_post(url + '/setLeague', league_dict)
+        #     print(res)
+        #     self.db.hg3535_wq_league.insert(league_list)
+
+        """赛事"""
+        # competition = self.db.hg3535_wq_competition.find_one({"match_id": match_id})
+        # match_list = []
+        # if competition:
+        #     print('网球赛事已存在,修改网球赛事四状态')
+        #     is_morningplate = competition['is_morningplate']
+        #     is_rollball = competition['is_rollball']
+        #     is_stringscene = competition['is_stringscene']
+        #     is_today = competition['is_today']
+        #     status = competition['status']
+        #     match_date = competition['match_date']
+        #     match_time = competition['match_time']
+        #     us_time = competition['us_time']
+        #     if is_rollball != 1 or status != 1:
+        #         match_dict = {"game_code": "wq", "title": "match", "source": "hg3535"}
+        #         match_key = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
+        #                      "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
+        #                      "half_match_id", "is_today", 'rule']
+        #         match_value = [team_home, team_guest, league_id, 1, match_id, match_date, match_time, tag_number,
+        #                        "hg3535", 1, is_morningplate, is_stringscene, us_time, uuid, 0, is_today, '']
+        #         match_data = dict(zip(match_key, match_value))
+        #         match_list.append(match_data)
+        #         match_dict['data'] = match_list
+        #         res = Helper.async_post(url + '/setMatch', match_dict)
+        #         print(res)
+        #         self.db.hg3535_wq_competition.insert(match_list)
+        #         self.db.hg3535_wq_competition.update({'match_id': str(match_id)},
+        #                                              {"$set": {"is_rollball": 1, "status": 1}},
+        #                                              upsert=True)
+        #     else:
+        #         print("网球赛事已存在,网球赛事状态时间未改变,不做修改")
+        # else:
+        #     is_rollball = 1
+        #     is_today = 0
+        #     is_morningplate = 0
+        #     is_stringscene = 0
+        #     match_dict = {"game_code": "wq", "title": "match", "source": "hg3535"}
+        #     match_key = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
+        #                  "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
+        #                  "half_match_id", "is_today", 'rule']
+        #     match_value = [team_home, team_guest, league_id, 1, match_id, r_ctime, "00:00", tag_number,
+        #                    "hg3535", is_rollball, is_morningplate, is_stringscene, utime, uuid, 0, is_today, '']
+        #     match_data = dict(zip(match_key, match_value))
+        #     match_list.append(match_data)
+        #     match_dict['data'] = match_list
+        #     res = Helper.async_post(url + '/setMatch', match_dict)
+        #     print(res)
+        #     self.db.hg3535_wq_competition.insert(match_list)
+
+        """赔率"""
+        try:
+            res = self.db.hg3535_wq_odds.find_one({'match_id': str(match_id), 'pt': pt})
+            odds_only_list = res['odds_only']
+        except:
+            res = ''
+            odds_only_list = []
+        data_list = []
+        odds_onlys = []
+        # 滚球独赢
+        if kemps_dict:
+            for key, value in kemps_dict.items():
+                if value:
+                    sole_str = 'kemps' + 'key' + '0' + str(match_id) + 'hg3535'
+                    sole = Helper.genearte_MD5(sole_str)
+                    odds_str = 'kemps' + str(key) + '0' + '0' + str(value) + 'hg3535' + str(match_id)
+                    odds_only = Helper.genearte_MD5(odds_str)
+                    kemps_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
+                                 "condition", "odds_only", "sole", "source", "type", "team"]
+                    kemps_value = [match_id, league_id, key, "0", 0, 'kemps', value, '',
+                                   odds_only, sole, "hg3535", "0", ""]
+                    kemps_data = dict(zip(kemps_key, kemps_value))
+                    odds_onlys.append(odds_only)
+                    if odds_only not in odds_only_list:
+                        data_list.append(kemps_data)
+        # 滚球让盘
+        if concedes_dict:
+            for key, value in concedes_dict.items():
+                if value:
+                    sole_str = 'concedes' + 'key' + '0' + str(match_id) + 'hg3535'
+                    sole = Helper.genearte_MD5(sole_str)
+                    odds_str = 'concedes' + str(key) + '0' + str(concedes_dict_rule[key]) + str(
+                        value) + 'hg3535' + str(match_id)
+                    odds_only = Helper.genearte_MD5(odds_str)
+                    condition = fuhao(concedes_dict_rule[key])
+                    concedes_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
+                                    "condition", "odds_only", "sole", "source", "type", "team"]
+                    concedes_value = [match_id, league_id, key, "0", 0, 'concede', value, condition,
+                                      odds_only, sole, "hg3535", "0", ""]
+                    concedes_data = dict(zip(concedes_key, concedes_value))
+                    odds_onlys.append(odds_only)
+                    if odds_only not in odds_only_list:
+                        data_list.append(concedes_data)
+        # 滚球让局
+        if bureaus_dict:
+            for key, value in bureaus_dict.items():
+                if value:
+                    sole_str = 'bureaus' + 'key' + '0' + str(match_id) + 'hg3535'
+                    sole = Helper.genearte_MD5(sole_str)
+                    odds_str = 'bureaus' + str(key) + '0' + str(bureaus_dict_rule[key]) + str(
+                        value) + 'hg3535' + str(match_id)
+                    odds_only = Helper.genearte_MD5(odds_str)
+                    condition = fuhao(bureaus_dict_rule[key])
+                    bureaus_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
+                                   "condition", "odds_only", "sole", "source", "type", "team"]
+                    bureaus_value = [match_id, league_id, key, "0", 0, 'bureaus', value, condition,
+                                     odds_only, sole, "hg3535", "0", ""]
+                    bureaus_data = dict(zip(bureaus_key, bureaus_value))
+                    odds_onlys.append(odds_only)
+                    if odds_only not in odds_only_list:
+                        data_list.append(bureaus_data)
+        # 滚球总局数大小
+        if total_number_dict:
+            for key, value in total_number_dict.items():
+                if value:
+                    sole_str = 'total_number' + 'key' + '0' + str(match_id) + 'hg3535'
+                    sole = Helper.genearte_MD5(sole_str)
+                    odds_str = 'total_number' + str(key) + '0' + str(
+                        total_number_dict_rule[key]) + str(value) + 'hg3535' + str(match_id)
+                    odds_only = Helper.genearte_MD5(odds_str)
+                    condition = fuhao(total_number_dict_rule[key])
+                    total_number_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
+                                        "condition", "odds_only", "sole", "source", "type", "team"]
+                    total_number_value = [match_id, league_id, key, "0", 0, 'bureaus', value,
+                                          condition, odds_only, sole, "hg3535", "0", ""]
+                    total_number_data = dict(zip(total_number_key, total_number_value))
+                    odds_onlys.append(odds_only)
+                    if odds_only not in odds_only_list:
+                        data_list.append(total_number_data)
+        # 滚球总局数单双
+        if odd_evens_dict:
+            for key, value in odd_evens_dict.items():
+                if value:
+                    condition = odd_evens_dict_rule[key]
+                    odds_str = "odd_evens" + key + '0' + str(odd_evens_dict_rule[key]) + str(
+                        value) + "hg3535" + str(match_id)
+                    sole_str = "odd_evens" + "key" + '0' + str(match_id) + "hg3535"
+                    odds_only = Helper.genearte_MD5(odds_str)
+                    sole = Helper.genearte_MD5(sole_str)
+                    odds_onlys.append(odds_only)
+                    odd_evens_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
+                                     "condition", "odds_only", "sole", "source", "type", "team"]
+                    odd_evens_value = [match_id, league_id, key, "0", 0, 'odd_evens', value,
+                                       condition, odds_only, sole, "hg3535", "0", ""]
+                    odd_evens_data = dict(zip(odd_evens_key, odd_evens_value))
+                    if odds_only not in odds_only_list:
+                        data_list.append(odd_evens_data)
+        odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid",
+                    "is_stringscene", "utime", "pt"]
+        odds_value = ["wq", "odds", match_id, league_id, data_list, "hg3535", odds_onlys, tag_number, uuid,
+                      0, utime, pt]
+        odds_dict = dict(zip(odds_key, odds_value))
+        # print(odds_dict)
+        if data_list:
+            res_data = Helper.async_post(url + '/setOdds', odds_dict)
+            print(res_data)
+            if "成功" in res_data:
+                if res:
+                    self.db.hg3535_wq_odds.update({'match_id': match_id, 'pt': pt}, {
+                        '$set': {"data": data_list, "odds_only": odds_onlys, "utime": utime}}, upsert=True)
+                else:
+                    self.db.hg3535_wq_odds.insert(odds_dict)
+
+        # 赛事结果
+        da_list = []
+        wq_rball = {"lg_id": league_id, "home_player_name": team_home, "guest_player_name": team_guest,
+                    "home_player_let_plate": '', "guest_player_let_plate": '', "home_player_let_inning": "",
+                    "guest_player_let_inning": "", "all_inning": "", "home_player_score": score_home,
+                    "guest_player_score": score_guest,
+                    "status": 1, "first_score_player": "", "last_score_player": "",
+                    "first_inning_score": score_dict['one_score'],
+                    "second_inning_score": score_dict['second_score'], "third_inning_score": score_dict['third_score'],
+                    "match_winer_player": "", "update_time": "",
+                    "match_time": time_game, "match_process": jijie, "tag": tag_number, "match_id": match_id,
+                    "source": "hg3535",
+                    "match_score": score_dict['current_point_home_guest'], "ctime": ctime, "inning": "",
+                    "strat_time": "", "uuid": uuid, "result_mark": score_dict
+                    }
+
+        da_list.append(wq_rball)
+        r_data_dict = {
+            "game_code": "wq",
+            "title": "match_result_r",
+            "source": "hg3535",
+            "data": da_list
+        }
+        if da_list:
+            try:
+                res = Helper.async_post(url + '/setMatchResult', r_data_dict)
+                print(res)
+            except Exception as e:
+                logger.warning('滚球接口数据异常, 提交失败')
+                logger.warning(e)

+ 315 - 0
hg3535/pipeline/wangqiu.py

@@ -0,0 +1,315 @@
+import datetime
+import pymongo
+import time
+import logging
+from .ball_func import fuhao
+from ..utils.helper import Helper
+from .ball_func import get_pcode, new_time, out_time
+from concurrent.futures import ThreadPoolExecutor
+from requests_futures.sessions import FuturesSession
+
+
+class Wangqiupipeline(object):
+    def open_spider(self, spider):
+        self.mongo = pymongo.MongoClient(host="192.168.2.200", username="kaiyou", password="kaiyou", port=27017)
+        self.db = self.mongo['kaiyou']
+        self.session = FuturesSession(executor=ThreadPoolExecutor(max_workers=10))
+
+    def process_item(self, item, spider):
+        wq_odds = []
+        logger = logging.getLogger(__name__)
+        url = 'http://admin.5gogo.com'
+        # logger.warning(query.addErrback(self.handle_error, item, spider))
+        # 联赛id
+        league_id = item['league_id']
+        # 联赛名
+        league_name = item['league_name']
+        # result = item['result']
+        # 比赛id
+        match_id = item['game_id']
+        # print(game_id)
+        # 球队1
+        team_home = item['team_home']
+        # 球队2
+        team_guest = item['team_guest']
+        # 数量(97>)
+        tag_number = item['number']
+        # 比赛状态
+        zhuangtai = item['zhuangtai']
+        # 日期
+        # data_game = item['data_game']
+        try:
+            data_game = item['data_game'].split("/")
+            month = str(data_game[1].strip())
+            day = str(data_game[0])
+        except Exception as e:
+            logger.warning(e)
+            data_game = item['data_game'].split(" ")
+            months = str(data_game[1].strip())
+            month_dict = {'Jan': '01', 'Feb': '02', 'Mar': '03', 'Apr': '04', 'May': '05', 'Jun': '06', 'Jul': '07',
+                          'Aug': '08', 'Sep': '09', 'Oct': '10', 'Nov': '11', 'Dec': '12'}
+            month = month_dict[months]
+            day = str(data_game[0])
+        # 比赛时间
+        time_game = str(item['time_game'])
+        # 比赛时间,时间戳
+        ctime = "2019" + "-" + month + "-" + day + " " + time_game + ":00"
+        r_ctime = "2019" + "-" + month + "-" + day
+        # 现在时间,时间戳
+        utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
+        expire_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() + 60))
+        # 队1分数
+        score_home = item['score_home']
+        # 队2分数
+        score_guest = item['score_guest']
+        # 第几节
+        jijie = item['jijie']
+        # 球队得分
+        qiudui = item['qiudui']
+        pt = item['pt']
+        # 让盘
+        concedes_dict = item['concedes_dict']
+        concedes_dict_rule = item['concedes_dict_rule']
+        # 冠军
+        kemps_dict = item['kemps_dict']
+        # 让局
+        bureaus_dict = item['bureaus_dict']
+        bureaus_dict_rule = item['bureaus_dict_rule']
+        # 总局数大小
+        total_number_dict = item['total_number_dict']
+        total_number_dict_rule = item['total_number_dict_rule']
+        # 总决赛单双
+        odd_evens_dict = item['odd_evens_dict']
+        odd_evens_dict_rule = item['odd_evens_dict_rule']
+
+        us_time = ctime
+        match_date, match_time, time3 = new_time(ctime)
+        n_time = out_time(time3, 3)
+        uuid = Helper.genearte_MD5(league_name + 'hg3535')
+
+        """联赛"""
+        last_time = '2019-12-31 23:59:59'
+        league_dict = {"game_code": "wq", "title": "league", "source": "hg3535"}
+        league_list = []
+
+        league_key = ["name_chinese", "kind", "match_mode", "if_stop", "last_time", "lg_id", "source", "uuid"]
+        league_value = [league_name, "1", "1", "0", last_time, league_id, "hg3535", uuid]
+        league_data = dict(zip(league_key, league_value))
+        league_list.append(league_data)
+        league_dict['data'] = league_list
+        # print(league_list)
+        # print(league_dict)
+        if self.db.hg3535_wq_league.find({'lg_id': league_id}).count() < 1:
+            res = Helper.async_post(url + '/setLeague', league_dict)
+            print(res)
+            self.db.hg3535_wq_league.insert(league_list)
+
+        """赛事"""
+        competition = self.db.hg3535_wq_competition.find_one({"match_id": match_id})
+        match_list = []
+        if competition:
+            print('赛事已存在,修改赛事四状态')
+            is_morningplate = competition['is_morningplate']
+            is_rollball = competition['is_rollball']
+            is_stringscene = competition['is_stringscene']
+            is_today = competition['is_today']
+            lmtime = competition['match_time']
+            if pt == 3:
+                if is_stringscene != 1 or lmtime != match_time:
+                    match_dict = {"game_code": "wq", "title": "match", "source": "hg3535"}
+                    match_key = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
+                                 "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
+                                 "half_match_id", "is_today", 'rule']
+                    match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number,
+                                   "hg3535", is_rollball, is_morningplate, 1, us_time, uuid, 0, is_today, '']
+                    match_data = dict(zip(match_key, match_value))
+                    match_list.append(match_data)
+                    match_dict['data'] = match_list
+                    # print(match_list)
+                    # print(match_dict)
+                    res = Helper.async_post(url + '/setMatch', match_dict)
+                    print(res)
+                    self.db.hg3535_wq_competition.update({'match_id': match_id},
+                                                         {"$set": {"is_stringscene": 1, 'match_time': match_time}},
+                                                         upsert=True)
+            if pt == 2:
+                if is_morningplate != 1 or lmtime != match_time:
+                    match_dict = {"game_code": "wq", "title": "match", "source": "hg3535"}
+                    match_key = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
+                                 "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
+                                 "half_match_id", "is_today", 'rule']
+                    match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number,
+                                   "hg3535", is_rollball, 1, is_stringscene, us_time, uuid, 0, is_today, '']
+                    match_data = dict(zip(match_key, match_value))
+                    match_list.append(match_data)
+                    match_dict['data'] = match_list
+                    # print(match_list)
+                    # print(match_dict)
+                    res = Helper.async_post(url + '/setMatch', match_dict)
+                    print(res)
+                    self.db.hg3535_wq_competition.update({'match_id': match_id},
+                                                         {"$set": {"is_morningplate": 1, 'match_time': match_time}},
+                                                         upsert=True)
+            if pt == 1:
+                if is_today != 1 or lmtime != match_time:
+                    match_dict = {"game_code": "wq", "title": "match", "source": "hg3535"}
+                    match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
+                                 "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
+                                 "half_match_id", "is_today", 'rule']
+                    match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number,
+                                   "hg3535", is_rollball, is_morningplate, is_stringscene, us_time, uuid, 0, 1, '']
+                    match_data = dict(zip(match_kay, match_value))
+                    match_list.append(match_data)
+                    match_dict['data'] = match_list
+                    # print(match_list)
+                    # print(match_dict)
+                    res = Helper.async_post(url + '/setMatch', match_dict)
+                    print(res)
+                    self.db.hg3535_wq_competition.update({'match_id': match_id},
+                                                         {"$set": {"is_today": 1, 'match_time': match_time}},
+                                                         upsert=True)
+            else:
+                print("赛事已存在,赛事状态时间未改变,不做修改")
+        else:
+            if pt == 3:
+                is_rollball = 0
+                is_today = 0
+                is_morningplate = 0
+                is_stringscene = 1
+            elif pt == 2:
+                is_rollball = 0
+                is_today = 0
+                is_morningplate = 1
+                is_stringscene = 0
+            else:
+                is_today = 1
+                is_rollball = 0
+                is_morningplate = 0
+                is_stringscene = 0
+            match_dict = {"game_code": "wq", "title": "match", "source": "hg3535"}
+            match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time", "tag",
+                         "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
+                         "half_match_id", "is_today", 'rule']
+            match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number, "hg3535",
+                           is_rollball, is_morningplate, is_stringscene, us_time, uuid, 0, is_today, '']
+            match_data = dict(zip(match_kay, match_value))
+            match_list.append(match_data)
+            match_dict['data'] = match_list
+            res = Helper.async_post(url + '/setMatch', match_dict)
+            print(res)
+            self.db.hg3535_wq_competition.insert(match_list)
+
+        """赔率"""
+        try:
+            result = self.db.hg3535_wq_odds.find_one({'match_id': match_id, 'pt': pt})
+            odds_only_list = result['odds_only']
+        except:
+            result = ''
+            odds_only_list = []
+        wangqiu = item['wangqiu']
+        data_list = []
+        odds_onlys = []
+        # 让盘
+        if concedes_dict:
+            for key, value in concedes_dict.items():
+                sole_str = 'dishes' + 'concedes' + str(key) + str(match_id) + 'hg3535'
+                sole = Helper.genearte_MD5(sole_str)
+                odds_str = 'dishes' + 'concedes' + str(key) + str(match_id) + 'hg3535' + str(concedes_dict_rule[key]) + str(
+                    value)
+                odds_only = Helper.genearte_MD5(odds_str)
+                condition = fuhao(concedes_dict_rule[key])
+                concedes_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
+                                     "odds_only", "sole", "source", "type", "team"]
+                concedes_dict_value = [match_id, league_id, key, '0', '0', 'dishes', value, condition,
+                                       odds_only, sole, 'hg3535', '0', '']
+                concedes_dict_data = dict(zip(concedes_dict_key, concedes_dict_value))
+                odds_onlys.append(odds_only)
+                if odds_only not in odds_only_list:
+                    data_list.append(concedes_dict_data)
+        # 让局
+        if bureaus_dict:
+            for key, value in bureaus_dict.items():
+                sole_str = 'bureau' + str(key) + str(match_id) + 'hg3535'
+                sole = Helper.genearte_MD5(sole_str)
+                odds_str = 'bureau' + str(key) + str(match_id) + 'hg3535' + str(bureaus_dict_rule[key]) + str(
+                    value)
+                odds_only = Helper.genearte_MD5(odds_str)
+                condition = fuhao(bureaus_dict_rule[key])
+                bureaus_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
+                                    "odds_only", "sole", "source", "type", "team"]
+                bureaus_dict_value = [match_id, league_id, key, '0', '0', 'bureau', value, condition,
+                                      odds_only, sole, 'hg3535', '0', '']
+                bureaus_dict_data = dict(zip(bureaus_dict_key, bureaus_dict_value))
+                odds_onlys.append(odds_only)
+                if odds_only not in odds_only_list:
+                    data_list.append(bureaus_dict_data)
+        # 总局数大小
+        if total_number_dict:
+            for key, value in total_number_dict.items():
+                sole_str = 'total_number' + str(key) + str(match_id) + 'hg3535'
+                sole = Helper.genearte_MD5(sole_str)
+                odds_str = 'total_number' + str(key) + str(match_id) + 'hg3535' + str(
+                    total_number_dict_rule[key]) + str(value)
+                odds_only = Helper.genearte_MD5(odds_str)
+                condition = fuhao(total_number_dict_rule[key])
+                total_number_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
+                                         "condition",
+                                         "odds_only", "sole", "source", "type", "team"]
+                total_number_dict_value = [match_id, league_id, key, '0', '0', 'total_number', value, condition,
+                                           odds_only, sole, 'hg3535', '0', '']
+                total_number_dict_data = dict(zip(total_number_dict_key, total_number_dict_value))
+                odds_onlys.append(odds_only)
+                if odds_only not in odds_only_list:
+                    data_list.append(total_number_dict_data)
+        # 总决赛单双
+        if odd_evens_dict:
+            for key, value in odd_evens_dict.items():
+                sole_str = 'two_game_sides' + str(key) + str(match_id) + 'hg3535'
+                sole = Helper.genearte_MD5(sole_str)
+                odds_str = 'two_game_sides' + str(key) + str(match_id) + 'hg3535' + str(odd_evens_dict_rule[key]) + str(
+                    value)
+                odds_only = Helper.genearte_MD5(odds_str)
+                condition = fuhao(odd_evens_dict_rule[key])
+                odd_evens_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
+                                      "odds_only", "sole", "source", "type", "team"]
+                odd_evens_dict_value = [match_id, league_id, key, '0', '0', 'two_game_sides', value, condition,
+                                        odds_only, sole, 'hg3535', '0', '']
+                odd_evens_dict_data = dict(zip(odd_evens_dict_key, odd_evens_dict_value))
+                odds_onlys.append(odds_only)
+                if odds_only not in odds_only_list:
+                    data_list.append(odd_evens_dict_data)
+        # 冠军
+        if kemps_dict:
+            for key, value in kemps_dict.items():
+                sole_str = 'kemp' + str(key) + str(match_id) + 'hg3535'
+                sole = Helper.genearte_MD5(sole_str)
+                odds_str = 'kemp' + str(key) + str(match_id) + 'hg3535' + '2' + str(value)
+                odds_only = Helper.genearte_MD5(odds_str)
+                kemps_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
+                                  "odds_only", "sole", "source", "type", "team"]
+                kemps_dict_value = [match_id, league_id, key, '0', '0', 'kemp', value, '',
+                                    odds_only, sole, 'hg3535', '0', '']
+                kemps_dict_data = dict(zip(kemps_dict_key, kemps_dict_value))
+                odds_onlys.append(odds_only)
+                if odds_only not in odds_only_list:
+                    data_list.append(kemps_dict_data)
+        if pt == 3:
+            ris_stringscene = 1
+        else:
+            ris_stringscene = 0
+        odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid",
+                    "is_stringscene", "utime", "pt"]
+        odds_value = ["wq", "odds", match_id, league_id, data_list, "hg3535", odds_onlys, tag_number, uuid,
+                      ris_stringscene, utime, pt]
+        odds_dict = dict(zip(odds_key, odds_value))
+        # print(odds_dict)
+        # print(123)
+        if data_list:
+            res = Helper.async_post(url + '/setOdds', odds_dict)
+            print(res)
+            if '成功' in res:
+                if result:
+                    self.db.hg3535_wq_odds.update({'match_id': match_id, 'pt': pt}, {
+                        '$set': {"data": data_list, "odds_only": odds_onlys, "utime": utime}}, upsert=True)
+                else:
+                    self.db.hg3535_wq_odds.insert(odds_dict)

+ 1 - 1
hg3535/pipeline/zuqiu.py

@@ -2,7 +2,7 @@ import datetime
 import pymongo
 import time
 import logging
-from ball_func import fuhao
+from .ball_func import fuhao
 from ..utils.helper import Helper
 from .ball_func import get_pcode, new_time
 from concurrent.futures import ThreadPoolExecutor

BIN
hg3535/spiders/__pycache__/__init__.cpython-36.pyc


BIN
hg3535/spiders/__pycache__/bangqiu.cpython-36.pyc


BIN
hg3535/spiders/__pycache__/bq_jieshu.cpython-36.pyc


BIN
hg3535/spiders/__pycache__/guanjun.cpython-36.pyc


BIN
hg3535/spiders/__pycache__/lanqiu.cpython-36.pyc


BIN
hg3535/spiders/__pycache__/liansai.cpython-36.pyc


BIN
hg3535/spiders/__pycache__/lq_jieshu.cpython-36.pyc


BIN
hg3535/spiders/__pycache__/roll_bangqiu.cpython-36.pyc


BIN
hg3535/spiders/__pycache__/roll_lanqiu.cpython-36.pyc


BIN
hg3535/spiders/__pycache__/roll_wangqiu.cpython-36.pyc


BIN
hg3535/spiders/__pycache__/roll_zuqiu.cpython-36.pyc


BIN
hg3535/spiders/__pycache__/wangqiu.cpython-36.pyc


BIN
hg3535/spiders/__pycache__/wq_jieshu.cpython-36.pyc


BIN
hg3535/spiders/__pycache__/wqbodan.cpython-36.pyc


BIN
hg3535/spiders/__pycache__/zq_jieshu.cpython-36.pyc


BIN
hg3535/spiders/__pycache__/zuqiu.cpython-36.pyc


+ 68 - 17
hg3535/spiders/bangqiu.py

@@ -15,15 +15,17 @@ class BqrangqiuSpider(scrapy.Spider):
     allowed_domains = ['hg3535z.com']
     custom_settings = {
         "ITEM_PIPELINES": {
-            "hg3535.pipeline.Bangqiupipeline": 300,
+            "hg3535.pipeline.bangqiu.Bangqiupipeline": 300,
         },
-        'LOG_LEVEL': 'DEBUG',
-        'LOG_FILE': "../hg3535/log/bangqiu_{}_{}_{}.log".format(to_day.year, to_day.month, to_day.day)
+        # 'LOG_LEVEL': 'DEBUG',
+        # 'LOG_FILE': "../hg3535/log/bangqiu_{}_{}_{}.log".format(to_day.year, to_day.month, to_day.day)
     }
 
     def start_requests(self):
         for y in range(1, 4):
-            url = 'https://hg3535z.com/odds2/d/getodds?sid=4&pt=' + str(y) + '&ubt=am&pn=0&sb=2&dc=null&pid=0'
+            # url = 'https://hg3535z.com/odds2/d/getodds?sid=4&pt=' + str(y) + '&ubt=am&pn=0&sb=2&dc=null&pid=0'
+            url = 'https://odata.jiushan6688.com/odds6i/d/getodds/zh-cn/sid/4/pt/' + str(
+                y) + '/ubt/am/pn/0/sb/2/dc/null/pid/0'
             yield scrapy.Request(url=url, callback=self.parse, meta={'pt': y}, dont_filter=True)
 
     def parse(self, response):
@@ -42,13 +44,16 @@ class BqrangqiuSpider(scrapy.Spider):
                     for new_result in new_results:
                         game_id = str(new_result['i'][16])
                         if pt == 1:
-                            url = "https://hg3535z.com/odds2/d/getamodds?eid=" + game_id + "&iip=false&ubt=am&isp=false"
+                            # url = "https://hg3535z.com/odds2/d/getamodds?eid=" + game_id + "&iip=false&ubt=am&isp=false"
+                            url = "https://odata.jiushan6688.com/odds6i/d/getamodds/zh-cn/eid/" + game_id + "/iip/false/ubt/am/isp/false"
                             yield Request(url=url, callback=self.parse_each, meta={'pt': pt}, dont_filter=True)
                         if pt == 2:
-                            url = "https://hg3535z.com/odds2/d/getamodds?eid=" + game_id + "&iip=false&ubt=am&isp=false"
+                            # url = "https://hg3535z.com/odds2/d/getamodds?eid=" + game_id + "&iip=false&ubt=am&isp=false"
+                            url = "https://odata.jiushan6688.com/odds6i/d/getamodds/zh-cn/eid/" + game_id + "/iip/false/ubt/am/isp/false"
                             yield Request(url=url, callback=self.parse_each, meta={'pt': pt}, dont_filter=True)
                         if pt == 3:
-                            url = "https://hg3535z.com/odds2/d/getamodds?eid=" + game_id + "&iip=false&ubt=am&isp=true"
+                            # url = "https://hg3535z.com/odds2/d/getamodds?eid=" + game_id + "&iip=false&ubt=am&isp=true"
+                            url = "https://odata.jiushan6688.com/odds6i/d/getamodds/zh-cn/eid/" + game_id + "/iip/false/ubt/am/isp/true"
                             yield Request(url=url, callback=self.parse_each, meta={'pt': pt}, dont_filter=True)
 
     def parse_each(self, response):
@@ -70,9 +75,10 @@ class BqrangqiuSpider(scrapy.Spider):
             # 联赛名
             league_name = new_datas["c"]["n"]
             new_data = new_datas["es"]
+            item = Bangqiu()
             for result in new_data:
                 if result['pci']["ctid"] is 0:
-                    item = Bangqiu()
+
                     # 比赛id
                     game_id = str(result['k'])
                     # 球队1
@@ -95,7 +101,7 @@ class BqrangqiuSpider(scrapy.Spider):
                     jijie = result['i'][12]
                     # 球队得分
                     qiudui = result['pci'].get('ctn', "")
-# --------------------------------------------------让球分割线-----------------------------------------------------------
+                    # --------------------------------------------------让球分割线-----------------------------------------------------------
                     concedes_dict = {}
                     concedes_dict_rule = {}
                     try:
@@ -113,7 +119,7 @@ class BqrangqiuSpider(scrapy.Spider):
                         concedes_dict['concede_home'] = ""
                         concedes_dict_rule['concede_guest'] = ""
                         concedes_dict['concede_guest'] = ""
-# 让球 前5局-------------------------------------------------------------------------------------------------------------
+                    # 让球 前5局-------------------------------------------------------------------------------------------------------------
                     try:
                         concedes = result['o']["ahf5in"]["v"]
                         concedes_dict_rule['five_concede_home'] = concedes[1]
@@ -129,7 +135,7 @@ class BqrangqiuSpider(scrapy.Spider):
                         concedes_dict['five_concede_home'] = ""
                         concedes_dict_rule['five_concede_guest'] = ""
                         concedes_dict['five_concede_guest'] = ""
-# ---------------------------------------------------独赢----------------------------------------------------------------
+                    # ---------------------------------------------------独赢----------------------------------------------------------------
                     capots_dict = {}
                     try:
                         capots = result['o']["ml"]["v"]
@@ -139,7 +145,7 @@ class BqrangqiuSpider(scrapy.Spider):
                     except:
                         capots_dict['capot_home'] = ""
                         capots_dict['capot_guest'] = ""
-# ---------------------------------------------------总得分:大/小--------------------------------------------------------
+                    # ---------------------------------------------------总得分:大/小--------------------------------------------------------
 
                     total_size_dict = {}
                     total_size_dict_rule = {}
@@ -158,7 +164,7 @@ class BqrangqiuSpider(scrapy.Spider):
                         total_size_dict['total_size_big'] = ""
                         total_size_dict_rule['total_size_small'] = ""
                         total_size_dict['total_size_small'] = ""
-# 总得分: 大/小 前5局-----------------------------------------------------------------------------------------------------
+                    # 总得分: 大/小 前5局-----------------------------------------------------------------------------------------------------
                     try:
                         total_sizes = result['o']["ouf5in"]["v"]
                         total_size_dict_rule['five_total_size_big'] = total_sizes[1]
@@ -175,7 +181,7 @@ class BqrangqiuSpider(scrapy.Spider):
                         total_size_dict_rule['five_total_size_small'] = ""
                         total_size_dict['five_total_size_small'] = ""
 
-# ------------------------------------------------------总得分:单/双-----------------------------------------------------
+                    # ------------------------------------------------------总得分:单/双-----------------------------------------------------
                     odd_evens_dict = {}
                     odd_evens_dict_rule = {}
                     try:
@@ -195,8 +201,6 @@ class BqrangqiuSpider(scrapy.Spider):
                         odd_evens_dict['two_sides_double'] = ""
                         odd_evens_dict_rule['two_sides_single'] = ""
                         odd_evens_dict_rule['two_sides_double'] = ""
-# 球队得分大小  待采集----------------------------------------------------------------------------------------------------
-
                     # 联赛id
                     item['league_id'] = league_id
                     # 联赛名
@@ -236,5 +240,52 @@ class BqrangqiuSpider(scrapy.Spider):
                     item['odd_evens_dict'] = odd_evens_dict
                     item['odd_evens_dict_rule'] = odd_evens_dict_rule
                     item['bangqiu'] = bangqiu
-                    yield item
+                    # yield item
+
+                if result['pci']['ctid'] is 208:
+                    """球队得分大/小  主队"""
+                    team_score_home_dict = {}
+                    team_score_home_rule_dict = {}
+                    try:
+                        team_score_home = result['o']['ou']['v']
+                        team_score_home_rule_dict['team_score_big'] = team_score_home[1]
+                        team_score_home_rule_dict['team_score_small'] = team_score_home[3]
+                        if pt is 3:
+                            team_score_home_dict['team_score_big'] = float(team_score_home[5]) - 1
+                            team_score_home_dict['team_score_small'] = float(team_score_home[7]) - 1
+                        else:
+                            team_score_home_dict['team_score_big'] = team_score_home[5]
+                            team_score_home_dict['team_score_small'] = team_score_home[7]
+                    except:
+                        team_score_home_dict['team_score_big'] = ''
+                        team_score_home_rule_dict['team_score_big'] = ''
+                        team_score_home_dict['team_score_small'] = ''
+                        team_score_home_rule_dict['team_score_small'] = ''
+                    # 球队得分大/小  主队
+                    item['team_score_home_dict'] = team_score_home_dict
+                    item['team_score_home_rule_dict'] = team_score_home_rule_dict
+
+                if result['pci']['ctid'] is 209:
+                    """球队得分大/小  客队"""
+                    team_score_guest_dict = {}
+                    team_score_guest_rule_dict = {}
+                    try:
+                        team_score_guest = result['o']['ou']['v']
+                        team_score_guest_rule_dict['team_score_big'] = team_score_guest[1]
+                        team_score_guest_rule_dict['team_score_small'] = team_score_guest[3]
+                        if pt is 3:
+                            team_score_guest_dict['team_score_big'] = float(team_score_guest[5]) - 1
+                            team_score_guest_dict['team_score_small'] = float(team_score_guest[7]) - 1
+                        else:
+                            team_score_guest_dict['team_score_big'] = team_score_guest[5]
+                            team_score_guest_dict['team_score_small'] = team_score_guest[7]
+                    except:
+                        team_score_guest_dict['team_score_big'] = ''
+                        team_score_guest_rule_dict['team_score_big'] = ''
+                        team_score_guest_dict['team_score_small'] = ''
+                        team_score_guest_rule_dict['team_score_small'] = ''
+                    # 球队得分大/小  客队
+                    item['team_score_guest_dict'] = team_score_guest_dict
+                    item['team_score_guest_rule_dict'] = team_score_guest_rule_dict
 
+            yield item

+ 64 - 52
hg3535/spiders/lanqiu.py

@@ -5,7 +5,7 @@ import json
 import scrapy
 from scrapy.http import Request
 
-from .. items import Lanqiu
+from ..items import Lanqiu
 
 
 def rangqiu_daxiao(inner, pt):
@@ -39,7 +39,6 @@ def danshaung_fun(inner):
 
 
 class LanqiuSpider(scrapy.Spider):
-
     name = "lanqiu"
     to_day = datetime.datetime.now()
     allowed_domains = ['hg3535z.com']
@@ -56,7 +55,8 @@ class LanqiuSpider(scrapy.Spider):
         # newall_lists = ['am', 'ftht1x2', 'oe', 'tg', 'htft', 'cs', 'fglg', 'or']
         for y in range(1, 4):
             # url = 'https://hg3535z.com/odds2/d/getodds?sid=2&pt='+str(y)+'&ubt=am&pn=0&sb=2&dc=null&pid=0'
-            url = "https://odata.jiushan6688.com/odds6i/d/getodds/zh-cn/sid/2/pt/" + str(y) + "/ubt/am/pn/0/sb/2/dc/null/pid/0"
+            url = "https://odata.jiushan6688.com/odds6i/d/getodds/zh-cn/sid/2/pt/" + str(
+                y) + "/ubt/am/pn/0/sb/2/dc/null/pid/0"
             yield scrapy.Request(url=url, callback=self.parse, dont_filter=True, meta={'pt': y})
             # yield scrapy.Request(url=url, callback=self.parse, meta={'pt': y}, dont_filter=True)
 
@@ -77,14 +77,18 @@ class LanqiuSpider(scrapy.Spider):
                     for new_result in new_results:
                         game_id = str(new_result['i'][16])
                         if pt == 1:
-                            url = "https://hg3535z.com/odds2/d/getamodds?eid=" + game_id + "&iip=false&ubt=am&isp=false"
+                            # url = "https://hg3535z.com/odds2/d/getamodds?eid=" + game_id + "&iip=false&ubt=am&isp=false"
+                            url = "https://odata.jiushan6688.com/odds6i/d/getamodds/zh-cn/eid/" + game_id + "/iip/false/ubt/am/isp/false"
                             yield Request(url=url, callback=self.parse_each, meta={'pt': pt}, dont_filter=True)
                         if pt == 2:
-                            url = "https://hg3535z.com/odds2/d/getamodds?eid=" + game_id + "&iip=false&ubt=am&isp=false"
+                            # url = "https://hg3535z.com/odds2/d/getamodds?eid=" + game_id + "&iip=false&ubt=am&isp=false"
+                            url = "https://odata.jiushan6688.com/odds6i/d/getamodds/zh-cn/eid/" + game_id + "/iip/false/ubt/am/isp/false"
                             yield Request(url=url, callback=self.parse_each, meta={'pt': pt}, dont_filter=True)
                         if pt == 3:
-                            url = "https://hg3535z.com/odds2/d/getamodds?eid=" + game_id + "&iip=false&ubt=am&isp=true"
+                            # url = "https://hg3535z.com/odds2/d/getamodds?eid=" + game_id + "&iip=false&ubt=am&isp=true"
+                            url = "https://odata.jiushan6688.com/odds6i/d/getamodds/zh-cn/eid/" + game_id + "/iip/false/ubt/am/isp/true"
                             yield Request(url=url, callback=self.parse_each, meta={'pt': pt}, dont_filter=True)
+
     def parse_each(self, response):
         try:
             new_datas = json.loads(response.text)['eg']
@@ -148,12 +152,13 @@ class LanqiuSpider(scrapy.Spider):
                     qiudui = result['pci'].get('ctn', "")
                     data.append(qiudui)
 
-# ----------------------------------------让球分割线---------------------------------------------------------------------
+                    # ----------------------------------------让球分割线---------------------------------------------------------------------
                     try:
                         concedes = result['o']["ah"]["v"]
                         # print(concedes)
                         # 主队让球条件,主队让球赔率,客队让球条件,客队让球赔率
-                        concede_home_rule,concede_home,concede_guest_rule,concede_guest=rangqiu_daxiao(inner=concedes, pt=pt)
+                        concede_home_rule, concede_home, concede_guest_rule, concede_guest = rangqiu_daxiao(
+                            inner=concedes, pt=pt)
                         concedes_dict_rule['concede_home'] = concede_home_rule
                         concedes_dict['concede_home'] = concede_home
                         concedes_dict_rule['concede_guest'] = concede_guest_rule
@@ -171,7 +176,8 @@ class LanqiuSpider(scrapy.Spider):
                     try:
                         half_concedes = result['o']["ah1st"]["v"]
                         # 上半场 主队让球条件
-                        half_concede_home_rule, half_concede_home, half_concede_guest_rule, half_concede_guest=rangqiu_daxiao(inner=half_concedes, pt=pt)
+                        half_concede_home_rule, half_concede_home, half_concede_guest_rule, half_concede_guest = rangqiu_daxiao(
+                            inner=half_concedes, pt=pt)
                         concedes_dict_rule['half_concede_home'] = half_concede_home_rule
                         concedes_dict['half_concede_home'] = half_concede_home
                         concedes_dict_rule['half_concede_guest'] = half_concede_guest_rule
@@ -190,7 +196,8 @@ class LanqiuSpider(scrapy.Spider):
                     # 第一节让球
                     try:
                         one_concedes = result['o']["ahq1"]["v"]
-                        one_concede_home_rule,one_concede_home,one_concede_guest_rule,one_concede_guest = rangqiu_daxiao(inner=one_concedes, pt=pt)
+                        one_concede_home_rule, one_concede_home, one_concede_guest_rule, one_concede_guest = rangqiu_daxiao(
+                            inner=one_concedes, pt=pt)
                         concedes_dict_rule['one_concede_home'] = one_concede_home_rule
                         concedes_dict['one_concede_home'] = one_concede_home
                         concedes_dict_rule['one_concede_guest'] = one_concede_guest_rule
@@ -208,7 +215,8 @@ class LanqiuSpider(scrapy.Spider):
                     # 第二节让球
                     try:
                         two_concedes = result['o']["ahq2"]["v"]
-                        two_concede_home_rule,two_concede_home,two_concede_guest_rule,two_concede_guest = rangqiu_daxiao(inner=two_concedes, pt=pt)
+                        two_concede_home_rule, two_concede_home, two_concede_guest_rule, two_concede_guest = rangqiu_daxiao(
+                            inner=two_concedes, pt=pt)
                         concedes_dict_rule['two_concede_home'] = two_concede_home_rule
                         concedes_dict['two_concede_home'] = two_concede_home
                         concedes_dict_rule['two_concede_guest'] = two_concede_guest_rule
@@ -225,7 +233,8 @@ class LanqiuSpider(scrapy.Spider):
                     # 第三节让球
                     try:
                         three_concedes = result['o']["ahq3"]["v"]
-                        three_concede_home_rule,three_concede_home,three_concede_guest_rule,three_concede_guest = rangqiu_daxiao(inner=three_concedes, pt=pt)
+                        three_concede_home_rule, three_concede_home, three_concede_guest_rule, three_concede_guest = rangqiu_daxiao(
+                            inner=three_concedes, pt=pt)
                         concedes_dict_rule['three_concede_home'] = three_concede_home_rule
                         concedes_dict['three_concede_home'] = three_concede_home
                         concedes_dict_rule['three_concede_guest'] = three_concede_guest_rule
@@ -243,7 +252,8 @@ class LanqiuSpider(scrapy.Spider):
                     # 第四节让球
                     try:
                         four_concedes = result['o']["ahq4"]["v"]
-                        four_concede_home_rule,four_concede_home,four_concede_guest_rule,four_concede_guest = rangqiu_daxiao(inner=four_concedes, pt=pt)
+                        four_concede_home_rule, four_concede_home, four_concede_guest_rule, four_concede_guest = rangqiu_daxiao(
+                            inner=four_concedes, pt=pt)
                         concedes_dict_rule['four_concede_home'] = four_concede_home_rule
                         concedes_dict['four_concede_home'] = four_concede_home
                         concedes_dict_rule['four_concede_guest'] = four_concede_guest_rule
@@ -258,11 +268,12 @@ class LanqiuSpider(scrapy.Spider):
                         concedes_dict['four_concede_home'] = None
                         concedes_dict_rule['four_concede_guest'] = None
                         concedes_dict['four_concede_guest'] = None
-# ----------------------------------------总分大小分割线 - ---------------------------------------------------------------
+                    # ----------------------------------------总分大小分割线 - ---------------------------------------------------------------
                     # 全场总分大小
                     try:
                         total_sizes = result['o']["ou"]["v"]
-                        total_sizes_big_rule,total_sizes_big,total_sizes_small_rule,total_sizes_small = rangqiu_daxiao(inner=total_sizes, pt=pt)
+                        total_sizes_big_rule, total_sizes_big, total_sizes_small_rule, total_sizes_small = rangqiu_daxiao(
+                            inner=total_sizes, pt=pt)
                         total_sizes_dict_rule["total_size_big"] = total_sizes_big_rule
                         total_sizes_dict["total_size_big"] = total_sizes_big
                         total_sizes_dict_rule["total_size_small"] = total_sizes_small_rule
@@ -279,7 +290,8 @@ class LanqiuSpider(scrapy.Spider):
                     # 上半场总分大小
                     try:
                         half_total_sizes = result['o']["ou1st"]["v"]
-                        half_total_sizes_big_rule,half_total_sizes_big,half_total_sizes_small_rule,half_total_sizes_small = rangqiu_daxiao(inner=half_total_sizes, pt=pt)
+                        half_total_sizes_big_rule, half_total_sizes_big, half_total_sizes_small_rule, half_total_sizes_small = rangqiu_daxiao(
+                            inner=half_total_sizes, pt=pt)
                         total_sizes_dict_rule["half_total_size_big"] = half_total_sizes_big_rule
                         total_sizes_dict["half_total_size_big"] = half_total_sizes_big
                         total_sizes_dict_rule["half_total_size_small"] = half_total_sizes_small_rule
@@ -296,7 +308,8 @@ class LanqiuSpider(scrapy.Spider):
                     # 第一节总分大小
                     try:
                         one_total_sizes = result['o']["ou1st"]["v"]
-                        one_total_sizes_big_rule,one_total_size_big,one_total_sizes_small_rule,one_total_sizes_small = rangqiu_daxiao(inner=one_total_sizes, pt=pt)
+                        one_total_sizes_big_rule, one_total_size_big, one_total_sizes_small_rule, one_total_sizes_small = rangqiu_daxiao(
+                            inner=one_total_sizes, pt=pt)
                         total_sizes_dict_rule["one_total_size_big"] = one_total_sizes_big_rule
                         total_sizes_dict["one_total_size_big"] = one_total_size_big
                         total_sizes_dict_rule["one_total_size_small"] = one_total_sizes_small_rule
@@ -313,7 +326,8 @@ class LanqiuSpider(scrapy.Spider):
                     # 第二节场总分大小
                     try:
                         two_total_sizes = result['o']["ou1st"]["v"]
-                        two_total_sizes_big_rule,two_total_sizes_big,two_total_sizes_small_rule,two_total_sizes_small = rangqiu_daxiao(inner=two_total_sizes, pt=pt)
+                        two_total_sizes_big_rule, two_total_sizes_big, two_total_sizes_small_rule, two_total_sizes_small = rangqiu_daxiao(
+                            inner=two_total_sizes, pt=pt)
                         total_sizes_dict_rule["two_total_size_big"] = two_total_sizes_big_rule
                         total_sizes_dict["two_total_size_big"] = two_total_sizes_big
                         total_sizes_dict_rule["two_total_size_small"] = two_total_sizes_small_rule
@@ -330,7 +344,8 @@ class LanqiuSpider(scrapy.Spider):
                     # 第三节总分大小
                     try:
                         three_total_sizes = result['o']["ou1st"]["v"]
-                        three_total_sizes_big_rule,three_total_sizes_big,three_total_sizes_small_rule,three_total_sizes_small = rangqiu_daxiao(inner=three_total_sizes, pt=pt)
+                        three_total_sizes_big_rule, three_total_sizes_big, three_total_sizes_small_rule, three_total_sizes_small = rangqiu_daxiao(
+                            inner=three_total_sizes, pt=pt)
                         total_sizes_dict_rule["three_total_size_big"] = three_total_sizes_big_rule
                         total_sizes_dict["three_total_size_big"] = three_total_sizes_big
                         total_sizes_dict_rule["three_total_size_small"] = three_total_sizes_small_rule
@@ -347,7 +362,8 @@ class LanqiuSpider(scrapy.Spider):
                     # 第四节总分大小
                     try:
                         four_total_sizes = result['o']["ou1st"]["v"]
-                        four_total_sizes_big_rule,four_total_sizes_big,four_total_sizes_small_rule,four_total_sizes_small = rangqiu_daxiao(inner=four_total_sizes, pt=pt)
+                        four_total_sizes_big_rule, four_total_sizes_big, four_total_sizes_small_rule, four_total_sizes_small = rangqiu_daxiao(
+                            inner=four_total_sizes, pt=pt)
                         total_sizes_dict_rule["four_total_size_big"] = four_total_sizes_big_rule
                         total_sizes_dict["four_total_size_big"] = four_total_sizes_big
                         total_sizes_dict_rule["four_total_size_small"] = four_total_sizes_small_rule
@@ -362,7 +378,7 @@ class LanqiuSpider(scrapy.Spider):
                         total_sizes_dict_rule["four_total_size_small"] = None
                         total_sizes_dict["four_total_size_small"] = None
 
-# ----------------------------------------总分单双分割线------------------------------------------------------------------
+                    # ----------------------------------------总分单双分割线------------------------------------------------------------------
                     # 全场 总分单双
                     try:
                         odd_evens = result['o']["oe"]["v"]
@@ -413,7 +429,6 @@ class LanqiuSpider(scrapy.Spider):
                         odd_evens_dict["one_two_sides_double"] = None
                         odd_evens_dict_rule['one_two_sides_double'] = '双'
 
-
                     # 总分:单/双-第二节
                     try:
                         two_odd_evens = result['o']["oeq2"]["v"]
@@ -448,8 +463,6 @@ class LanqiuSpider(scrapy.Spider):
                         odd_evens_dict["three_two_sides_double"] = None
                         odd_evens_dict_rule['three_two_sides_double'] = '双'
 
-
-
                     # 总分:单/双-第四节
                     try:
                         four_odd_evens = result['o']["oeq4"]["v"]
@@ -466,8 +479,8 @@ class LanqiuSpider(scrapy.Spider):
                         odd_evens_dict["four_two_sides_double"] = None
                         odd_evens_dict_rule['four_two_sides_double'] = '双'
 
-# ----------------------------------------球队得分最后一位数分割线---------------------------------------------------------
-                # 球队得分最后一位数 主队
+                    # ----------------------------------------球队得分最后一位数分割线---------------------------------------------------------
+                    # 球队得分最后一位数 主队
 
                     try:
                         last_numbers = result["p-o"][0]['o']
@@ -483,8 +496,10 @@ class LanqiuSpider(scrapy.Spider):
                     # 球队得分最后一位数 客队
                     try:
                         new_last_numbers = result["p-o"][1]['o']
-                        last_guest = {new_last_numbers[0][0]: new_last_numbers[0][2], new_last_numbers[1][0]: new_last_numbers[1][2],
-                                      new_last_numbers[2][0]: new_last_numbers[2][2], new_last_numbers[3][0]: new_last_numbers[3][2],
+                        last_guest = {new_last_numbers[0][0]: new_last_numbers[0][2],
+                                      new_last_numbers[1][0]: new_last_numbers[1][2],
+                                      new_last_numbers[2][0]: new_last_numbers[2][2],
+                                      new_last_numbers[3][0]: new_last_numbers[3][2],
                                       new_last_numbers[4][0]: new_last_numbers[4][2]}
                         # if new_last_numbers:
                         #     for new_last_number in new_last_numbers:
@@ -492,7 +507,7 @@ class LanqiuSpider(scrapy.Spider):
                     except:
                         last_guest = {}
                     last_numbers_dict["last_guest"] = last_guest
-# ------------------------------------------------------独赢分割线---------------------------------------------------------
+                    # ------------------------------------------------------独赢分割线---------------------------------------------------------
 
                     # 独赢
                     try:
@@ -578,8 +593,8 @@ class LanqiuSpider(scrapy.Spider):
                         capots_dict["four_capot_home"] = None
                         capots_dict["four_capot_guest"] = None
 
-# ---------------------------------------------------华丽分割线列表es[1]--------------------------------------------------
-            # 球队得分 全场主队 home
+                # ---------------------------------------------------华丽分割线列表es[1]--------------------------------------------------
+                # 球队得分 全场主队 home
                 if result['pci']['ctid'] == 41:
                     try:
                         score_home = new_data[1]
@@ -589,7 +604,8 @@ class LanqiuSpider(scrapy.Spider):
                     if score_home:
                         try:
                             score_homes = score_home["o"]["ou"]['v']
-                            score_home_big_rule,score_home_big,score_home_small_rule,score_home_small = rangqiu_daxiao(inner=score_homes)
+                            score_home_big_rule, score_home_big, score_home_small_rule, score_home_small = rangqiu_daxiao(
+                                inner=score_homes)
                             team_scores_dict_rule["score_home_big"] = score_home_big_rule
                             team_scores_dict["score_home_big"] = score_home_big
                             team_scores_dict_rule["score_home_small"] = score_home_small_rule
@@ -607,7 +623,8 @@ class LanqiuSpider(scrapy.Spider):
                         try:
                             half_score_homes = score_home['o']['ou1st']['v']
                             # 球队得分 上半场主队 大条件
-                            half_score_home_big_rule,half_score_home_big,half_score_home_small_rule,half_score_home_small = rangqiu_daxiao(inner=half_score_homes)
+                            half_score_home_big_rule, half_score_home_big, half_score_home_small_rule, half_score_home_small = rangqiu_daxiao(
+                                inner=half_score_homes)
                             team_scores_dict_rule["half_score_home_big"] = half_score_home_big_rule
                             team_scores_dict["half_score_home_big"] = half_score_home_big
                             team_scores_dict_rule["half_score_home_small"] = half_score_home_small_rule
@@ -625,7 +642,8 @@ class LanqiuSpider(scrapy.Spider):
                         # 球队得分:主队-大 / 小-第一节
                         try:
                             one_score_homes = score_home['o']["ouq1"]["v"]
-                            one_score_home_big_rule,one_score_home_big,one_score_home_small_rule,one_score_home_small = rangqiu_daxiao(inner=one_score_homes)
+                            one_score_home_big_rule, one_score_home_big, one_score_home_small_rule, one_score_home_small = rangqiu_daxiao(
+                                inner=one_score_homes)
                             team_scores_dict_rule["one_score_home_big"] = one_score_home_big_rule
                             team_scores_dict["one_score_home_big"] = one_score_home_big
                             team_scores_dict_rule["one_score_home_small"] = one_score_home_small_rule
@@ -643,7 +661,8 @@ class LanqiuSpider(scrapy.Spider):
                         # 球队得分:主队-大 / 小-第一节
                         try:
                             two_score_homes = score_home['o']["ouq2"]["v"]
-                            two_score_home_big_rule,two_score_home_big,two_score_home_small_rule,two_score_home_small = rangqiu_daxiao(inner=two_score_homes)
+                            two_score_home_big_rule, two_score_home_big, two_score_home_small_rule, two_score_home_small = rangqiu_daxiao(
+                                inner=two_score_homes)
                             team_scores_dict_rule["two_score_home_big"] = two_score_home_big_rule
                             team_scores_dict["two_score_home_big"] = two_score_home_big
                             team_scores_dict_rule["two_score_home_small"] = two_score_home_small_rule
@@ -661,7 +680,8 @@ class LanqiuSpider(scrapy.Spider):
                         # 球队得分:主队-大 / 小-第一节
                         try:
                             three_score_homes = score_home['o']["ouq3"]["v"]
-                            three_score_home_big_rule,three_score_home_big,three_score_home_small_rule,three_score_home_small = rangqiu_daxiao(inner=three_score_homes)
+                            three_score_home_big_rule, three_score_home_big, three_score_home_small_rule, three_score_home_small = rangqiu_daxiao(
+                                inner=three_score_homes)
                             team_scores_dict_rule["three_score_home_big"] = three_score_home_big_rule
                             team_scores_dict["three_score_home_big"] = three_score_home_big
                             team_scores_dict_rule["three_score_home_small"] = three_score_home_small_rule
@@ -679,7 +699,8 @@ class LanqiuSpider(scrapy.Spider):
                         # 球队得分:主队-大 / 小-第四节
                         try:
                             four_score_homes = score_home['o']["ouq4"]["v"]
-                            four_score_home_big_rule,four_score_home_big,four_score_home_small_rule,four_score_home_small = rangqiu_daxiao(inner=four_score_homes)
+                            four_score_home_big_rule, four_score_home_big, four_score_home_small_rule, four_score_home_small = rangqiu_daxiao(
+                                inner=four_score_homes)
                             team_scores_dict_rule["four_score_home_big"] = four_score_home_big_rule
                             team_scores_dict["four_score_home_big"] = four_score_home_big
                             team_scores_dict_rule["four_score_home_small"] = four_score_home_small_rule
@@ -694,9 +715,8 @@ class LanqiuSpider(scrapy.Spider):
                             team_scores_dict_rule["four_score_home_small"] = None
                             team_scores_dict["four_score_home_small"] = None
 
-
-# ---------------------------------------------------华丽分割线列表es[2]--------------------------------------------------
-            # 球队得分 客队 guest
+                # ---------------------------------------------------华丽分割线列表es[2]--------------------------------------------------
+                # 球队得分 客队 guest
                 if result['pci']['ctid'] == 42:
                     try:
                         score_guest = new_data[2]
@@ -706,7 +726,8 @@ class LanqiuSpider(scrapy.Spider):
                         try:
                             # 球队得分: 大 / 小
                             score_guests = score_guest["o"]["ou"]['v']
-                            score_guest_big_rule,score_guest_big,score_guest_small_rule,score_guest_small = rangqiu_daxiao(inner=score_guests)
+                            score_guest_big_rule, score_guest_big, score_guest_small_rule, score_guest_small = rangqiu_daxiao(
+                                inner=score_guests)
                             team_scores_dict_rule["score_guest_big"] = score_guest_big_rule
                             team_scores_dict["score_guest_big"] = score_guest_big
                             team_scores_dict_rule["score_guest_small"] = score_guest_small_rule
@@ -724,7 +745,8 @@ class LanqiuSpider(scrapy.Spider):
                         # 球队得分 上半场客队 guest
                         try:
                             half_score_guests = score_guest["o"]['ou1st']['v']
-                            half_score_guest_big_rule,half_score_guest_big,half_score_guest_small_rule,half_score_guest_small = rangqiu_daxiao(inner=half_score_guests)
+                            half_score_guest_big_rule, half_score_guest_big, half_score_guest_small_rule, half_score_guest_small = rangqiu_daxiao(
+                                inner=half_score_guests)
                             team_scores_dict_rule["half_score_guest_big"] = half_score_guest_big_rule
                             team_scores_dict["half_score_guest_big"] = half_score_guest_big
                             team_scores_dict_rule["half_score_guest_small"] = half_score_guest_small_rule
@@ -840,13 +862,3 @@ class LanqiuSpider(scrapy.Spider):
             item['team_score_rule'] = team_scores_dict_rule
             item['lanqiu'] = lanqiu
             yield item
-
-
-
-
-
-
-
-
-
-

Diff do ficheiro suprimidas por serem muito extensas
+ 2 - 2
hg3535/spiders/roll_bangqiu.py


+ 50 - 53
hg3535/spiders/roll_wangqiu.py

@@ -26,6 +26,7 @@ def rangqiu_daxiao(inner):
     concede_guest = [concedeguest[i] for i in range(len(concedeguest)) if i % 2 == 1]
     return concede_home_rule, concede_home, concede_guest_rule, concede_guest
 
+
 def danshaung_fun(inner):
     odd_even = [inner[i] for i in range(len(inner)) if i % 2 == 1]
     # 全场 总分单
@@ -39,14 +40,18 @@ class WangqiuSpider(scrapy.Spider):
     name = "roll_wangqiu"
     to_day = datetime.datetime.now()
     allowed_domains = ['hg3535z.com']
-    start_urls = ['https://hg3535z.com/odds2/d/getodds?sid=3&pt=4&ubt=am&pn=0&sb=2&dc=null&pid=0'] # 滚球菜单 网球滚球列url
+    # start_urls = ['https://hg3535z.com/odds2/d/getodds?sid=3&pt=4&ubt=am&pn=0&sb=2&dc=null&pid=0']  # 滚球菜单 网球滚球列url
+    start_urls = [
+        'https://odata.jiushan6688.com/odds6i/d/getodds/zh-cn/sid/3/pt/4/ubt/am/pn/0/sb/2/dc/null/pid/0']  # 滚球菜单 网球滚球列url
     custom_settings = {
         "ITEM_PIPELINES": {
-            "hg3535.pipeline.Roll_Wangqiupipeline": 350,
+            # "hg3535.pipeline.Roll_Wangqiupipeline": 350,
+            "hg3535.pipeline.roll_wangqiu.Roll_Wangqiupipeline": 350,
         },
         # 'LOG_LEVEL': 'DEBUG',
         # 'LOG_FILE': "../hg3535/log/roll_wangqiu_{}_{}_{}.log".format(to_day.year, to_day.month, to_day.day)
     }
+
     # start_urls = ['http://hg3535z.com/odds2/d/getodds?sid=2&pt=3&ubt=am&pn=0&sb=2&dc=null&pid=0']
     # http: // hg3535z.com / odds2 / d / getamodds?eid = 3098030 & iip = false & ubt = am & isp = false
     # http://hg3535z.com/odds2/d/getodds?sid=2&pt=2&ubt=am&pn=0&sb=2&dc=null&pid=0
@@ -54,16 +59,18 @@ class WangqiuSpider(scrapy.Spider):
     def parse(self, response):
         datas = json.loads(response.text)
         # item = Today_all()
-        ids = jsonpath.jsonpath(datas, '$..i-ot[0]..egs..es..i[16]') # ids新列表
-        print(ids)
+        ids = jsonpath.jsonpath(datas, '$..i-ot[0]..egs..es..i[16]')  # ids新列表
+        # print(ids)
         if ids:
             ids = set(ids)
             for i in ids:
-                urls = 'https://www.hg3535z.com/odds2/d/getamodds?eid={}&iip=true&ubt=am&isp=false'.format(i)
-                print(urls)
-                yield Request(url=urls, callback=self.parse_other)
+                # urls = 'https://www.hg3535z.com/odds2/d/getamodds?eid={}&iip=true&ubt=am&isp=false'.format(i)
+                urls = 'https://odata.jiushan6688.com/odds6i/d/getamodds/zh-cn/eid/{}/iip/true/ubt/am/isp/false'.format(
+                    i)
+                # print(urls)
+                yield Request(url=urls, callback=self.parse_other, dont_filter=True)
 
-    def parse_other(self,response):
+    def parse_other(self, response):
         new_datas = json.loads(response.text).get('eg', "")
         try:
             pt = response.meta['pt']
@@ -106,7 +113,7 @@ class WangqiuSpider(scrapy.Spider):
                 # jijie = result['i'][12]
                 # 球队得分
                 qiudui = result['pci'].get('ctn', "")
-# ----------------------------------------让球分割线---------------------------------------------------------------------------
+                # ----------------------------------------让球分割线---------------------------------------------------------------------------
                 concedes_dict = {}
                 concedes_dict_rule = {}
                 try:
@@ -123,8 +130,8 @@ class WangqiuSpider(scrapy.Spider):
                     concedes_dict['dishes_guest'] = ""
                 # print(concedes_dict)
 
-# ----------------------------------------第一节让球分割线----------------------------------------------------------------
-                #第一节让盘
+                # ----------------------------------------第一节让球分割线----------------------------------------------------------------
+                # 第一节让盘
                 try:
                     # 第一节让球
                     one_concedes = result['o']["ahs1"]["v"]
@@ -138,7 +145,7 @@ class WangqiuSpider(scrapy.Spider):
                     concedes_dict_rule['one_dishes_guest'] = ""
                     concedes_dict['one_dishes_guest'] = ""
 
-# ----------------------------------------第二节让球分割线----------------------------------------------------------------
+                # ----------------------------------------第二节让球分割线----------------------------------------------------------------
 
                 # 第二节让盘
                 try:
@@ -153,9 +160,10 @@ class WangqiuSpider(scrapy.Spider):
                     concedes_dict_rule['two_dishes_guest'] = ""
                     concedes_dict['two_dishes_guest'] = ""
 
-# ---------------------------------------------------冠军  滚球是独赢-----------------------------------------------------
+                # ---------------------------------------------------冠军  滚球是独赢-----------------------------------------------------
                 kemps_dict = {}
                 try:
+                    # 滚球独赢
                     kemps = result['o']["ml"]["v"]
                     kemps_dict['kemp_home'] = kemps[1]
                     kemps_dict['kemp_guest'] = kemps[3]
@@ -173,7 +181,7 @@ class WangqiuSpider(scrapy.Spider):
                     kemps_dict['one_kemp_home'] = ""
                     kemps_dict['one_kemp_guest'] = ""
 
-                try: # 第二盘 独赢
+                try:  # 第二盘 独赢
                     kemps = result['o']["mls2"]["v"]
                     kemps_dict['two_kemp_home'] = kemps[1]
                     kemps_dict['two_kemp_guest'] = kemps[3]
@@ -181,7 +189,7 @@ class WangqiuSpider(scrapy.Spider):
                     kemps_dict['two_kemp_home'] = ""
                     kemps_dict["two_kemp_guest"] = ""
 
-# ---------------------------------------------------让局---------------------------------------------------------------
+                # ---------------------------------------------------让局---------------------------------------------------------------
 
                 bureaus_dict = {}
                 bureaus_dict_rule = {}
@@ -197,10 +205,10 @@ class WangqiuSpider(scrapy.Spider):
                     bureaus_dict_rule['concede_guest'] = ""
                     bureaus_dict['concede_guest'] = ""
 
-# -----------------------------------------------------总局数 第一盘:大/小------------------------------------------------
+                # -----------------------------------------------------总局数 第一盘:大/小------------------------------------------------
                 total_number_dict = {}
                 total_number_dict_rule = {}
-                try:  #总局数 滚球大小
+                try:  # 总局数 滚球大小
                     total_numbers = result['o']["oufts"]["v"]
                     total_number_dict_rule['total_number_big'] = total_numbers[1]
                     total_number_dict['total_number_big'] = total_numbers[5]
@@ -238,7 +246,6 @@ class WangqiuSpider(scrapy.Spider):
                     total_number_dict_rule["two_total_number_small"] = ""
                     total_number_dict["two_total_number_small"] = ""
 
-
                 # 第三节盘
                 try:
                     three_total_sizes = result['o']["ous3"]["v"]
@@ -252,13 +259,13 @@ class WangqiuSpider(scrapy.Spider):
                     total_number_dict_rule["three_total_number_small"] = ""
                     total_number_dict["three_total_number_small"] = ""
 
-# ------------------------------------------------------总局数:单/双-----------------------------------------------------
+                # ------------------------------------------------------总局数:单/双-----------------------------------------------------
                 odd_evens_dict = {}
                 odd_evens_dict_rule = {}
                 try:
                     odd_evens = result['o']["oefts"]["v"]
                     # 上半场 主队让球条件
-                    odd_evens_dict['two_sides_single'] = odd_evens[1] # 之前是odd_even_odd
+                    odd_evens_dict['two_sides_single'] = odd_evens[1]  # 之前是odd_even_odd
                     odd_evens_dict_rule['two_sides_single'] = "单"
                     odd_evens_dict['two_sides_double'] = odd_evens[3]
                     odd_evens_dict_rule['two_sides_double'] = "双"
@@ -271,22 +278,38 @@ class WangqiuSpider(scrapy.Spider):
 
                 # 盘,局,点
                 sq_dict = {}
+                # 每局比分
+                score_dict = {}
                 try:
                     saiqing = []
                     # h为第一个队伍,a为第二个队伍
-                    s = result['sb']['cp']
+                    s = result['sb']['cp']  # 当前比赛是第几节
                     cps = result['sb']['ps']
-                    # 队伍1
+                    # 队伍1 当前的大比分
                     h = result['sb']['h']
-                    # 队伍2
+                    # 队伍2 当前的大比分
                     a = result['sb']['a']
                     for cp in cps:
+                        # 当前比分
+                        if cp['p'] == 'p':
+                            score_dict['current_point_home_guest'] = str(cp['h']) + ':' + str(cp['a'])
+                        # 每局比分
+                        if cp['p'] == 's1':
+                            score_dict['one_score'] = str(cp['h']) + '-' + str(cp['a'])
+                        elif cp['p'] == 's2':
+                            score_dict['second_score'] = str(cp['h']) + '-' + str(cp['a'])
+                        elif cp['p'] == 's3':
+                            score_dict['third_score'] = str(cp['h']) + '-' + str(cp['a'])
+                        elif cp['p'] == 's4':
+                            score_dict['four_score'] = str(cp['h']) + '-' + str(cp['a'])
+                        elif cp['p'] == 's5':
+                            score_dict['five_score'] = str(cp['h']) + '-' + str(cp['a'])
                         cp.pop('e')
                         cp.pop('adv')
                         cp['cp'] = s
                         saiqing.append(cp)
                     sq_dict['ps'] = saiqing
-                    print(sq_dict)
+                    # print(sq_dict)
                 except:
                     sq_dict['ps'] = None
                     # 队伍1
@@ -316,9 +339,11 @@ class WangqiuSpider(scrapy.Spider):
                 item['score_home'] = h
                 # 队2分数
                 item['score_guest'] = a
-                # 第几节
+                # 当前第几节
                 item['jijie'] = s
                 item['pt'] = pt
+                # 每局比分
+                item['score_dict'] = score_dict
                 # 球队得分
                 item['qiudui'] = qiudui
                 # 让盘
@@ -337,31 +362,3 @@ class WangqiuSpider(scrapy.Spider):
                 item['odd_evens_dict_rule'] = odd_evens_dict_rule
                 item['sq_dict'] = sq_dict
                 yield item
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

+ 38 - 42
hg3535/spiders/wangqiu.py

@@ -11,21 +11,23 @@ from ..items import Wangqiu
 
 
 class LanqiuSpider(scrapy.Spider):
-
     name = "wangqiu"
     to_day = datetime.datetime.now()
     allowed_domains = ['hg3535z.com']
     custom_settings = {
         "ITEM_PIPELINES": {
-            "hg3535.pipeline.Wangqiupipeline": 300,
+            "hg3535.pipeline.wangqiu.Wangqiupipeline": 300,
         },
-        'LOG_LEVEL': 'DEBUG',
-        'LOG_FILE': "../hg3535/log/wangqiu_{}_{}_{}.log".format(to_day.year, to_day.month, to_day.day)
+        # 'LOG_LEVEL': 'DEBUG',
+        # 'LOG_FILE': "../hg3535/log/wangqiu_{}_{}_{}.log".format(to_day.year, to_day.month, to_day.day)
     }
+
     def start_requests(self):
         # newall_lists = ['am', 'ftht1x2', 'oe', 'tg', 'htft', 'cs', 'fglg', 'or']
         for y in range(1, 4):
-            url = 'https://hg3535z.com/odds2/d/getodds?sid=3&pt='+str(y)+'&ubt=am&pn=0&sb=2&dc=null&pid=0'
+            # url = 'https://hg3535z.com/odds2/d/getodds?sid=3&pt=' + str(y) + '&ubt=am&pn=0&sb=2&dc=null&pid=0'
+            url = 'https://odata.jiushan6688.com/odds6i/d/getodds/zh-cn/sid/3/pt/' + str(
+                y) + '/ubt/am/pn/0/sb/2/dc/null/pid/0'
             yield scrapy.Request(url=url, callback=self.parse, meta={'pt': y}, dont_filter=True)
 
     def parse(self, response):
@@ -44,14 +46,18 @@ class LanqiuSpider(scrapy.Spider):
                     for new_result in new_results:
                         game_id = str(new_result['i'][16])
                         if pt == 1:
-                            url = "https://hg3535z.com/odds2/d/getamodds?eid=" + game_id + "&iip=false&ubt=am&isp=false"
+                            # url = "https://hg3535z.com/odds2/d/getamodds?eid=" + game_id + "&iip=false&ubt=am&isp=false"
+                            url = "https://odata.jiushan6688.com/odds6i/d/getamodds/zh-cn/eid/" + game_id + "/iip/false/ubt/am/isp/false"
                             yield Request(url=url, callback=self.parse_each, meta={'pt': pt}, dont_filter=True)
                         if pt == 2:
-                            url = "https://hg3535z.com/odds2/d/getamodds?eid=" + game_id + "&iip=false&ubt=am&isp=false"
+                            # url = "https://hg3535z.com/odds2/d/getamodds?eid=" + game_id + "&iip=false&ubt=am&isp=false"
+                            url = "https://odata.jiushan6688.com/odds6i/d/getamodds/zh-cn/eid/" + game_id + "/iip/false/ubt/am/isp/false"
                             yield Request(url=url, callback=self.parse_each, meta={'pt': pt}, dont_filter=True)
                         if pt == 3:
-                            url = "https://hg3535z.com/odds2/d/getamodds?eid=" + game_id + "&iip=false&ubt=am&isp=true"
+                            # url = "https://hg3535z.com/odds2/d/getamodds?eid=" + game_id + "&iip=false&ubt=am&isp=true"
+                            url = "https://odata.jiushan6688.com/odds6i/d/getamodds/zh-cn/eid/" + game_id + "/iip/false/ubt/am/isp/true"
                             yield Request(url=url, callback=self.parse_each, meta={'pt': pt}, dont_filter=True)
+
     def parse_each(self, response):
         try:
             new_datas = json.loads(response.text)['eg']
@@ -91,7 +97,7 @@ class LanqiuSpider(scrapy.Spider):
                 jijie = result['i'][12]
                 # 球队得分
                 qiudui = result['pci'].get('ctn', "")
-# --------------------------------------------------让盘分割线-----------------------------------------------------------
+                # --------------------------------------------------让盘分割线-----------------------------------------------------------
                 concedes_dict = {}
                 concedes_dict_rule = {}
                 try:
@@ -109,7 +115,7 @@ class LanqiuSpider(scrapy.Spider):
                     concedes_dict['dishes_home'] = ""
                     concedes_dict_rule['dishes_guest'] = ""
                     concedes_dict['dishes_guest'] = ""
-# ---------------------------------------------------冠军----------------------------------------------------------------
+                # ---------------------------------------------------冠军----------------------------------------------------------------
                 kemps_dict = {}
                 try:
                     kemps = result['o']["ml"]["v"]
@@ -129,7 +135,7 @@ class LanqiuSpider(scrapy.Spider):
                     kemps_dict['one_kemp_home'] = ""
                     kemps_dict['one_kemp_guest'] = ""
 
-# ---------------------------------------------------让局---------------------------------------------------------------
+                # ---------------------------------------------------让局---------------------------------------------------------------
 
                 bureaus_dict = {}
                 bureaus_dict_rule = {}
@@ -149,8 +155,8 @@ class LanqiuSpider(scrapy.Spider):
                     bureaus_dict_rule['concede_guest'] = ""
                     bureaus_dict['concede_guest'] = ""
 
-# -----------------------------------------------------总局数:大/小------------------------------------------------------
-# 总局数大小第一盘 未采集
+                # -----------------------------------------------------总局数:大/小------------------------------------------------------
+                # 总局数大小第一盘 未采集
                 total_number_dict = {}
                 total_number_dict_rule = {}
                 try:
@@ -169,25 +175,25 @@ class LanqiuSpider(scrapy.Spider):
                     total_number_dict_rule['total_number_small'] = ""
                     total_number_dict['total_number_small'] = ""
                 # 第一节盘
-                try:
-                    one_total_sizes = result['o']["ous1"]["v"]
-                    total_number_dict_rule["one_total_number_big"] = one_total_sizes[1]
-                    total_number_dict["one_total_number_big"] = one_total_sizes[5]
-                    total_number_dict_rule["one_total_number_small"] = one_total_sizes[3]
-                    total_number_dict["one_total_number_small"] = one_total_sizes[7]
-                    if pt is 3:
-                        total_number_dict['total_number_big'] = float(one_total_sizes[5]) - 1
-                        total_number_dict['total_number_small'] = float(one_total_sizes[7]) - 1
-                    else:
-                        total_number_dict['total_number_big'] = one_total_sizes[5]
-                        total_number_dict['total_number_small'] = one_total_sizes[7]
-                except:
-                    total_number_dict_rule["one_total_number_big"] = ""
-                    total_number_dict["one_total_number_big"] = ""
-                    total_number_dict_rule["one_total_number_small"] = ""
-                    total_number_dict["one_total_number_small"] = ""
-
-# ------------------------------------------------------总局数:单/双-----------------------------------------------------
+                # try:
+                #     one_total_sizes = result['o']["ous1"]["v"]
+                #     total_number_dict_rule["one_total_number_big"] = one_total_sizes[1]
+                #     total_number_dict["one_total_number_big"] = one_total_sizes[5]
+                #     total_number_dict_rule["one_total_number_small"] = one_total_sizes[3]
+                #     total_number_dict["one_total_number_small"] = one_total_sizes[7]
+                #     if pt is 3:
+                #         total_number_dict['total_number_big'] = float(one_total_sizes[5]) - 1
+                #         total_number_dict['total_number_small'] = float(one_total_sizes[7]) - 1
+                #     else:
+                #         total_number_dict['total_number_big'] = one_total_sizes[5]
+                #         total_number_dict['total_number_small'] = one_total_sizes[7]
+                # except:
+                #     total_number_dict_rule["one_total_number_big"] = ""
+                #     total_number_dict["one_total_number_big"] = ""
+                #     total_number_dict_rule["one_total_number_small"] = ""
+                #     total_number_dict["one_total_number_small"] = ""
+
+                # ------------------------------------------------------总局数:单/双-----------------------------------------------------
                 odd_evens_dict = {}
                 odd_evens_dict_rule = {}
                 try:
@@ -247,13 +253,3 @@ class LanqiuSpider(scrapy.Spider):
                 item['odd_evens_dict_rule'] = odd_evens_dict_rule
                 item['wangqiu'] = wangqiu
                 yield item
-
-
-
-
-
-
-
-
-
-

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff