lanqiu.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. class ZuqiuPipeline(object):
  6. @defer.inlineCallbacks
  7. def process_item(self,item,spider):
  8. logger=logging.getLogger(__name__)
  9. logger.info("进入管道")
  10. out=defer.Deferred()
  11. reactor.callInThread(self._do_calculation,item,out)
  12. yield out
  13. def _do_calculation(self,item,out):
  14. #先保存联赛
  15. league_name = item['league']
  16. uuid = Helper.genearte_uuid(league_name)
  17. type=item['showtype']
  18. is_rollball,is_today,is_morningplate = 0,0,0
  19. if type=="FT":
  20. is_today=1
  21. elif type=="FU":
  22. is_morningplate=1
  23. elif type=="RB":
  24. is_rollball=1
  25. else:
  26. is_stringscene=1
  27. league_key = ["name_chinese", "kind", "match_mode", "if_stop", "last_time", "lg_id", "source", "uuid","is_rollball","is_today","is_morningplate","is_stringscene"]
  28. league_value = [league_name, "1", "1", "0", item['datetime'], item['id'], "hgg070", uuid,is_rollball,is_today,is_morningplate,is_stringscene]
  29. #赛事
  30. childer = dict(zip(league_key, league_value))
  31. #联赛
  32. obj = {"game_code": "lq", "title": "league", "source": "hgg070","data":[childer]}
  33. res=Helper.async_post(LEAGUE_URL,obj)
  34. if res:
  35. if res.get('status')==1:
  36. logging.warning("联赛提交成功,{}".format(res))
  37. #提交赛事
  38. lres=Helper.async_post(MATCH_URL,childer)
  39. if lres.get('status')==1:
  40. logging.warning("联赛提交成功,{}".format(res))
  41. else:
  42. logging.warning("联赛提交失败,{}".format(res))
  43. else:
  44. logging.warning("联赛提交失败,{}".format(res))
  45. else:
  46. logging.warning("联赛提交失败,{}".format(res))