| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- # import datetime
- import pymongo
- # import time
- import logging
- # import redis
- # from twisted.internet import defer, reactor
- import redis
- from ..settings import M_HOST, M_USER, M_PASSWORD, M_POST, M_DB, MATCH_STATUS
- from ..utils.helper import Helper
- from ..settings import R_HOST, R_PASSWORD, R_POST, R_DB
- # 滚球足球 插入
- class Jieshuqiupipeline(object):
- def open_spider(self, spider):
- self.mongo = pymongo.MongoClient(host=M_HOST, username=M_USER, password=M_PASSWORD, port=M_POST)
- self.db = self.mongo[M_DB]
- self.rls = redis.Redis(host=R_HOST, port=R_POST, db=R_DB, password=R_PASSWORD)
- # @defer.inlineCallbacks
- # def process_item(self, item, spider):
- # out = defer.Deferred()
- # reactor.callInThread(self._do_calculation, item, out)
- # yield out
- # defer.returnValue(item)
- # def _do_calculation(self, item, out):
- def process_item(self, item, spider):
- logger = logging.getLogger(__name__)
- ball = item['ball']
- match_id = item['match_id']
- # status = item['status']
- if ball == '足球':
- game_code = "zq"
- elif ball == '篮球':
- game_code = "lq"
- elif ball == '网球':
- game_code = "wq"
- else:
- game_code = "bq"
- # if status:
- # roll_status = 1
- # self.rls.srem('hg3535.gunqiu.ids', match_id)
- # else:
- # roll_status = 2
- status_dict = {"game_code": game_code, "title": "match_status", "source": "hg3535"}
- data_list = []
- data = {'match_id': match_id, 'status': 2, "is_rollball": 0, "is_today": 0, "is_morningplate": 0, "is_stringscene": 0, "is_horn": 0}
- data_list.append(data)
- status_dict['data'] = data_list
- res = Helper.async_post(MATCH_STATUS, status_dict)
- if res:
- if "成功" in res:
- self.db.match_status35.insert(status_dict)
- logger.info('{},赛事结果状态交成功, {}'.format(game_code, res))
- logger.info(status_dict)
- else:
- logger.warning('{},赛事结果状态交失败, {}'.format(game_code, res))
- logger.warning(status_dict)
- else:
- logger.warning('{},赛事结果状态接口异常提交失败, {}'.format(game_code, res))
- logger.warning(status_dict)
- # reactor.callFromThread(out.callback, item)
|