change.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import time
  2. # from venv import logger
  3. import redis
  4. from utils.helper import Helper
  5. from settings import R_HOST, R_PASSWORD, R_POST, R_DB, MATCH_STATUS
  6. def get_redis(k):
  7. rls = redis.Redis(host=R_HOST, port=R_POST, db=R_DB, password=R_PASSWORD)
  8. ids = rls.hgetall(k)
  9. return ids
  10. def Change_status(ids):
  11. if ids:
  12. for id, up_time in ids.items():
  13. match_id = id.decode()
  14. up_time = up_time.decode().split('&')
  15. last_time = float(up_time[0])
  16. game_code = up_time[1]
  17. new_time = time.time() - last_time
  18. if new_time > 900:
  19. status_dict = {"game_code": game_code, "title": "match_status", "source": "hg3535"}
  20. data_list = []
  21. data = {'match_id': match_id, 'status': 2, "is_rollball": 0, "is_today": 0, "is_morningplate": 0,
  22. "is_stringscene": 0, "is_horn": 0}
  23. data_list.append(data)
  24. status_dict['data'] = data_list
  25. res = Helper.async_post(MATCH_STATUS, status_dict)
  26. if res:
  27. if "成功" in res:
  28. # self.db.match_status35.insert(status_dict)
  29. print('{},赛事结果状态交成功, {}'.format(game_code, res))
  30. print(status_dict)
  31. else:
  32. print('{},赛事结果状态交失败, {}'.format(game_code, res))
  33. print(status_dict)
  34. else:
  35. print('{},赛事结果状态接口异常提交失败, {}'.format(game_code, res))
  36. print(status_dict)
  37. else:
  38. print('15分钟内, 暂无球类赛事结束或取消')
  39. if __name__ == '__main__':
  40. while True:
  41. ids = get_redis('hg3535.ball.ids')
  42. Change_status(ids)
  43. print('*****-------球类更新状态, 运行结束--------*****')
  44. time.sleep(30)