lq_sports.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import logging
  2. from twisted.internet import defer,reactor
  3. from ..utils.helper import Helper
  4. from ..settings import LEAGUE_URL,MATCH_URL
  5. import time
  6. class LqSportsPipeline(object):
  7. @defer.inlineCallbacks
  8. def process_item(self,item,spider):
  9. print('555555555555555555555555555555555555555555555555555555555555555555555')
  10. logger=logging.getLogger(__name__)
  11. logger.info("进入管道")
  12. out=defer.Deferred()
  13. reactor.callInThread(self._do_calculation,item,out)
  14. yield out
  15. def _do_calculation(self,item,out):
  16. #先保存联赛
  17. league_name = item['league']
  18. uuid = Helper.genearte_uuid(league_name)
  19. #是否串场
  20. if item['isP'] == 'P':
  21. ris_stringscene = 1
  22. else:
  23. ris_stringscene = 0
  24. # 现在时间,时间戳
  25. utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  26. odds_key = ["game_code", "title", "match_id", "lg_id","data", "source", "odds_only", "tag", "uuid",
  27. "is_stringscene", "utime", "pt", 'match_identity']
  28. odds_value = ["lq", "odds", item['match_id'], item['league_id'], item["content"],"hgg070", [], item['more_count'], uuid,
  29. ris_stringscene, utime, item['isP'], item["match_identity"]]
  30. #赛事
  31. childer = dict(zip(odds_key, odds_value))
  32. res=Helper.async_post(LEAGUE_URL,childer)
  33. if res:
  34. if res.get('status')==1:
  35. logging.warning("联赛提交成功,{}".format(res))
  36. else:
  37. logging.warning("联赛提交失败,{}".format(res))
  38. else:
  39. logging.warning("联赛提交失败,{}".format(res))