juan 6 tahun lalu
induk
melakukan
22b9ef7545
2 mengubah file dengan 22 tambahan dan 11 penghapusan
  1. 14 4
      hgg070_spider/pipelines/lq_sports.py
  2. 8 7
      hgg070_spider/spiders/lq_sports.py

+ 14 - 4
hgg070_spider/pipelines/lq_sports.py

@@ -2,7 +2,8 @@ import logging
 from twisted.internet import defer,reactor
 from ..utils.helper import Helper
 from ..settings import LEAGUE_URL,MATCH_URL
-class ZuqiuPipeline(object):
+import time
+class LqSportsPipeline(object):
     @defer.inlineCallbacks
     def process_item(self,item,spider):
         logger=logging.getLogger(__name__)
@@ -26,10 +27,19 @@ class ZuqiuPipeline(object):
             is_rollball=1
         else:
             is_stringscene=1
-        league_key = ["name_chinese", "kind", "match_mode", "if_stop", "last_time", "lg_id", "source", "uuid","is_rollball","is_today","is_morningplate","is_stringscene"]
-        league_value = [league_name, "1", "1", "0", item['datetime'], item['id'], "hgg070", uuid,is_rollball,is_today,is_morningplate,is_stringscene]
+        #是否串场
+        if item['isP'] == 'P':
+            ris_stringscene = 1
+        else:
+            ris_stringscene = 0
+        # 现在时间,时间戳
+        utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
+        odds_key = ["game_code", "title", "match_id", "lg_id","data", "source", "odds_only", "tag", "uuid",
+                    "is_stringscene", "utime", "pt", 'match_identity']
+        odds_value = ["lq", "odds", item['match_id'], item['gidm'], item["content"],"hgg070", [], item['more_count'], uuid,
+                      ris_stringscene, utime, item['isP'], item["match_identity"]]
         #赛事
-        childer = dict(zip(league_key, league_value))
+        childer = dict(zip(odds_key, odds_value))
         #联赛
         obj = {"game_code": "lq", "title": "league", "source": "hgg070","data":[childer]}
         res=Helper.async_post(LEAGUE_URL,obj)

+ 8 - 7
hgg070_spider/spiders/lq_sports.py

@@ -15,7 +15,7 @@ class LqSportsSpider(scrapy.Spider):
     remath = re.compile("篮球")
     custom_settings={
         "ITEM_PIPELINES": {
-            "hgg070_spider.pipelines.lanqiu.ZuqiuPipeline": 200,
+            "hgg070_spider.pipelines.lq_sports.LqSportsPipeline": 200,
         },
     }
     def start_requests(self):
@@ -75,11 +75,14 @@ class LqSportsSpider(scrapy.Spider):
         game=response.xpath("//game")
         for g in game:
             gid=g.xpath("./gid/text()").extract_first()
+            more_count = g.xpath("./more_count/text()").extract_first()
             data["gid"]=gid
-            yield scrapy.FormRequest(url=url,formdata=data,callback=self.getItem,dont_filter=True)
+            yield scrapy.FormRequest(url=url,formdata=data,callback=self.getItem,meta={"more_count":more_count,"isP":data["isP"]},dont_filter=True)
 
 
     def getItem(self,response):
+        more_count = response.meta["more_count"]
+        isP = response.meta["isP"]
         game_lists = []
         data=response.xpath("//game")
         if data:
@@ -106,16 +109,14 @@ class LqSportsSpider(scrapy.Spider):
                 datetime = gl['datetime'][:-8] + " " + gl['datetime'][-8:]
                 team_h = gl['team_h']
                 team_c = gl['team_c']
-                tag = 0
                 league_id = gl['gidm']
                 match_id = gl.get('gid', '')
-                match_uid = Helper.genearte_MD5(team_h + team_c + datetime)
+                match_uid = Helper.genearte_uuid(team_h + team_c + datetime)
                 for x in hgg:
                     try:
                         enabled = gl[x['prodds']]
                         if enabled == 'Y':
                             x['enabled'] = 1
-                            tag += 1
                         else:
                             x['enabled'] = 0
                     except:
@@ -154,9 +155,9 @@ class LqSportsSpider(scrapy.Spider):
                 item['updata'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
                 item['content'] = odd_list
                 item['gidm'] = league_id
-                item['tag'] = tag
+                item['more_count'] = more_count
                 item['league'] = gl["league"]
-                item['match_uid'] = match_uid
+                item['match_identity'] = match_uid
                 item['datetime'] = datetime
                 item['team_h'] = team_h
                 item['team_c'] = team_c