lq_sports.py 1.7 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. 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", [],
  29. item['more_count'], uuid,
  30. ris_stringscene, utime, item['isP'], item["match_identity"]]
  31. # 赛事
  32. childer = dict(zip(odds_key, odds_value))
  33. res = Helper.async_post(LEAGUE_URL, childer)
  34. if res:
  35. if res.get('status') == 1:
  36. logging.warning("联赛提交成功,{}".format(res))
  37. else:
  38. logging.warning("联赛提交失败,{}".format(res))
  39. else:
  40. logging.warning("联赛提交失败,{}".format(res))