aaaaa.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. logger = logging.getLogger(__name__)
  10. logger.info("进入管道")
  11. out = defer.Deferred()
  12. reactor.callInThread(self._do_calculation, item, out)
  13. yield out
  14. def _do_calculation(self, item, out):
  15. # 先保存联赛
  16. league_name = item['league']
  17. uuid = Helper.genearte_uuid(league_name)
  18. # 是否串场
  19. if item['isP'] == 'P':
  20. ris_stringscene = 1
  21. else:
  22. ris_stringscene = 0
  23. # 现在时间,时间戳
  24. utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  25. odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid",
  26. "is_stringscene", "utime", "pt", 'match_identity']
  27. odds_value = ["lq", "odds", item['match_id'], item['league_id'], item["content"], "hgg070", [],
  28. 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))