lq_sports.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. type=item['showtype']
  19. is_rollball,is_today,is_morningplate = 0,0,0
  20. if type=="FT":
  21. is_today=1
  22. elif type=="FU":
  23. is_morningplate=1
  24. elif type=="RB":
  25. is_rollball=1
  26. else:
  27. is_stringscene=1
  28. #是否串场
  29. if item['isP'] == 'P':
  30. ris_stringscene = 1
  31. else:
  32. ris_stringscene = 0
  33. # 现在时间,时间戳
  34. utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  35. odds_key = ["game_code", "title", "match_id", "lg_id","data", "source", "odds_only", "tag", "uuid",
  36. "is_stringscene", "utime", "pt", 'match_identity']
  37. odds_value = ["lq", "odds", item['match_id'], item['gidm'], item["content"],"hgg070", [], item['more_count'], uuid,
  38. ris_stringscene, utime, item['isP'], item["match_identity"]]
  39. #赛事
  40. childer = dict(zip(odds_key, odds_value))
  41. #联赛
  42. obj = {"game_code": "lq", "title": "league", "source": "hgg070","data":[childer]}
  43. res=Helper.async_post(LEAGUE_URL,obj)
  44. if res:
  45. if res.get('status')==1:
  46. logging.warning("联赛提交成功,{}".format(res))
  47. #提交赛事
  48. lres=Helper.async_post(MATCH_URL,childer)
  49. if lres.get('status')==1:
  50. logging.warning("联赛提交成功,{}".format(res))
  51. else:
  52. logging.warning("联赛提交失败,{}".format(res))
  53. else:
  54. logging.warning("联赛提交失败,{}".format(res))
  55. else:
  56. logging.warning("联赛提交失败,{}".format(res))