jieshu.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # import datetime
  2. import pymongo
  3. # import time
  4. import logging
  5. # import redis
  6. # from twisted.internet import defer, reactor
  7. import redis
  8. from ..settings import M_HOST, M_USER, M_PASSWORD, M_POST, M_DB, MATCH_STATUS
  9. from ..utils.helper import Helper
  10. from ..settings import R_HOST, R_PASSWORD, R_POST, R_DB
  11. # 滚球足球 插入
  12. class Jieshuqiupipeline(object):
  13. def open_spider(self, spider):
  14. self.mongo = pymongo.MongoClient(host=M_HOST, username=M_USER, password=M_PASSWORD, port=M_POST)
  15. self.db = self.mongo[M_DB]
  16. self.rls = redis.Redis(host=R_HOST, port=R_POST, db=R_DB, password=R_PASSWORD)
  17. # @defer.inlineCallbacks
  18. # def process_item(self, item, spider):
  19. # out = defer.Deferred()
  20. # reactor.callInThread(self._do_calculation, item, out)
  21. # yield out
  22. # defer.returnValue(item)
  23. # def _do_calculation(self, item, out):
  24. def process_item(self, item, spider):
  25. logger = logging.getLogger(__name__)
  26. ball = item['ball']
  27. match_id = item['match_id']
  28. # status = item['status']
  29. if ball == '足球':
  30. game_code = "zq"
  31. elif ball == '篮球':
  32. game_code = "lq"
  33. elif ball == '网球':
  34. game_code = "wq"
  35. else:
  36. game_code = "bq"
  37. # if status:
  38. # roll_status = 1
  39. # self.rls.srem('hg3535.gunqiu.ids', match_id)
  40. # else:
  41. # roll_status = 2
  42. status_dict = {"game_code": game_code, "title": "match_status", "source": "hg3535"}
  43. data_list = []
  44. data = {'match_id': match_id, 'status': 2, "is_rollball": 0, "is_today": 0, "is_morningplate": 0, "is_stringscene": 0, "is_horn": 0}
  45. data_list.append(data)
  46. status_dict['data'] = data_list
  47. res = Helper.async_post(MATCH_STATUS, status_dict)
  48. if res:
  49. if "成功" in res:
  50. self.db.match_status35.insert(status_dict)
  51. logger.info('{},赛事结果状态交成功, {}'.format(game_code, res))
  52. logger.info(status_dict)
  53. else:
  54. logger.warning('{},赛事结果状态交失败, {}'.format(game_code, res))
  55. logger.warning(status_dict)
  56. else:
  57. logger.warning('{},赛事结果状态接口异常提交失败, {}'.format(game_code, res))
  58. logger.warning(status_dict)
  59. # reactor.callFromThread(out.callback, item)