| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- import logging
- from twisted.internet import defer,reactor
- from ..utils.helper import Helper
- from ..settings import LEAGUE_URL,MATCH_URL
- import time
- class LqSportsPipeline(object):
- @defer.inlineCallbacks
- def process_item(self,item,spider):
- logger=logging.getLogger(__name__)
- logger.info("进入管道")
- out=defer.Deferred()
- reactor.callInThread(self._do_calculation,item,out)
- yield out
- def _do_calculation(self,item,out):
- #先保存联赛
- league_name = item['league']
- uuid = Helper.genearte_uuid(league_name)
- type=item['showtype']
- is_rollball,is_today,is_morningplate = 0,0,0
- if type=="FT":
- is_today=1
- elif type=="FU":
- is_morningplate=1
- elif type=="RB":
- is_rollball=1
- else:
- is_stringscene=1
- #是否串场
- 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(odds_key, odds_value))
- #联赛
- obj = {"game_code": "lq", "title": "league", "source": "hgg070","data":[childer]}
- res=Helper.async_post(LEAGUE_URL,obj)
- if res:
- if res.get('status')==1:
- logging.warning("联赛提交成功,{}".format(res))
- #提交赛事
- lres=Helper.async_post(MATCH_URL,childer)
- if lres.get('status')==1:
- logging.warning("联赛提交成功,{}".format(res))
- else:
- logging.warning("联赛提交失败,{}".format(res))
- else:
- logging.warning("联赛提交失败,{}".format(res))
- else:
- logging.warning("联赛提交失败,{}".format(res))
|