saiguo.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import pymongo
  2. import logging
  3. from twisted.internet import defer, reactor
  4. from ..settings import M_HOST, M_USER, M_PASSWORD, M_POST, M_DB, SAIGUO_RESULT
  5. from ..utils.helper import Helper
  6. # 滚球足球 插入
  7. class Jieshuqiupipeline(object):
  8. def open_spider(self, spider):
  9. self.mongo = pymongo.MongoClient(host=M_HOST, username=M_USER, password=M_PASSWORD, port=M_POST)
  10. self.db = self.mongo[M_DB]
  11. @defer.inlineCallbacks
  12. def process_item(self, item, spider):
  13. out = defer.Deferred()
  14. reactor.callInThread(self._do_calculation, item, out)
  15. yield out
  16. defer.returnValue(item)
  17. # def process_item(self, item, spider):
  18. def _do_calculation(self, item, out):
  19. logger = logging.getLogger(__name__)
  20. pt = item['pt']
  21. league_id = item["league_id"]
  22. league_name = item["league_name"]
  23. match_id = item["match_id"]
  24. match_date = item["match_date"]
  25. match_time = item["match_time"]
  26. h_name = item["home_team"]
  27. a_name = item["guest_team"]
  28. play_data = item["play_data"]
  29. if pt == 1:
  30. h_score = item["score_half"]
  31. f_score = item["score_full"]
  32. post_data = {'game_code': 'zq', "title": "result", "source": "hg3535", "data": []}
  33. data = {"league_id": league_id, "league_name": league_name, "match_date": match_date,
  34. "match_time": match_time, "home_team": h_name, "guest_team": a_name, "score_half": h_score,
  35. "score_full": f_score, "play_data": play_data, "match_id": match_id}
  36. post_data['data'].append(data)
  37. res = Helper.async_post(SAIGUO_RESULT, post_data)
  38. if res:
  39. if res.get('status') == 1:
  40. self.db.zq_saiguo35.insert(post_data)
  41. logger.info('{},赛事结果状态交成功, {}'.format('zq', res))
  42. logger.info(post_data)
  43. else:
  44. logger.warning('{},赛事结果状态交失败, {}'.format('zq', res))
  45. logger.warning(post_data)
  46. else:
  47. logger.warning('{},赛事结果状态接口异常提交失败, {}'.format('zq', res))
  48. logger.warning(post_data)
  49. elif pt == 2:
  50. h_score = item["score_half"]
  51. f_score = item["score_result"]
  52. x_score = item["score_below"]
  53. post_data = {'game_code': 'lq', "title": "result", "source": "hg3535", "data": []}
  54. data = {"league_id": league_id, "league_name": league_name, "match_date": match_date,
  55. "match_time": match_time, "home_team": h_name, "match_id": match_id,
  56. "guest_team": a_name, "score_half": h_score, "score_below": x_score, "score_result": f_score,
  57. "play_data": play_data}
  58. post_data['data'].append(data)
  59. res = Helper.async_post(SAIGUO_RESULT, post_data)
  60. if res:
  61. if res.get('status') == 1:
  62. self.db.lq_saiguo35.insert(post_data)
  63. logger.info('{},赛事结果状态交成功, {}'.format('lq', res))
  64. logger.info(post_data)
  65. else:
  66. logger.warning('{},赛事结果状态交失败, {}'.format('lq', res))
  67. logger.warning(post_data)
  68. else:
  69. logger.warning('{},赛事结果状态接口异常提交失败, {}'.format('lq', res))
  70. logger.warning(post_data)
  71. elif pt == 3:
  72. f_score = item["score_result"]
  73. post_data = {'game_code': 'wq', "title": "result", "source": "hg3535", "data": []}
  74. data = {"league_id": league_id, "league_name": league_name, "match_date": match_date,
  75. "match_time": match_time, "home_team": h_name, "guest_team": a_name, "score_result": f_score,
  76. "play_data": play_data, "match_id": match_id}
  77. post_data['data'].append(data)
  78. res = Helper.async_post(SAIGUO_RESULT, post_data)
  79. if res:
  80. if res.get('status') == 1:
  81. self.db.wq_saiguo35.insert(post_data)
  82. logger.info('{},赛事结果状态交成功, {}'.format('wq', res))
  83. logger.info(post_data)
  84. else:
  85. logger.warning('{},赛事结果状态交失败, {}'.format('wq', res))
  86. logger.warning(post_data)
  87. else:
  88. logger.warning('{},赛事结果状态接口异常提交失败, {}'.format('wq', res))
  89. logger.warning(post_data)
  90. else:
  91. h_score = item["score_half"]
  92. f_score = item["score_full"]
  93. post_data = {'game_code': 'bq', "title": "result", "source": "hg3535", "data": []}
  94. data = {"league_id": league_id, "league_name": league_name, "match_date": match_date,
  95. "match_time": match_time, "home_team": h_name, "guest_team": a_name, "score_half": h_score,
  96. "score_full": f_score, "play_data": play_data, "match_id": match_id}
  97. post_data['data'].append(data)
  98. res = Helper.async_post(SAIGUO_RESULT, post_data)
  99. if res:
  100. if res.get('status') == 1:
  101. self.db.bq_saiguo35.insert(post_data)
  102. logger.info('{},赛事结果状态交成功, {}'.format('bq', res))
  103. logger.info(post_data)
  104. else:
  105. logger.warning('{},赛事结果状态交失败, {}'.format('bq', res))
  106. logger.warning(post_data)
  107. else:
  108. logger.warning('{},赛事结果状态接口异常提交失败, {}'.format('bq', res))
  109. logger.warning(post_data)
  110. reactor.callFromThread(out.callback, item)