|
|
|
import random
|
|
|
|
import json
|
|
|
|
import time
|
|
|
|
|
|
|
|
from django_redis import get_redis_connection
|
|
|
|
|
|
|
|
RANDOM_DATA_API_LIST = ['cinema/plays', 'play/seat-status']
|
|
|
|
|
|
|
|
def random_params(_user_info, _handle_data):
|
|
|
|
if _user_info["api"] in RANDOM_DATA_API_LIST:
|
|
|
|
print('_user_info', _user_info)
|
|
|
|
print('_handle_data', _handle_data)
|
|
|
|
redis_key_api = f'dspt_api_{_user_info["user_ip"]}_{_user_info["member_type"]}_{_user_info["api"]}_random'
|
|
|
|
redis_conn = get_redis_connection()
|
|
|
|
if redis_conn.get(redis_key_api):
|
|
|
|
redis_conn.delete(redis_key_api)
|
|
|
|
data = {
|
|
|
|
'api': _user_info["api"],
|
|
|
|
'member_type': _user_info["member_type"],
|
|
|
|
'format': _user_info["format"],
|
|
|
|
'timestamp': int(time.time()*1000),
|
|
|
|
}
|
|
|
|
if _user_info["api"] == 'play/seat-status':
|
|
|
|
_user_data = get_ok_status_seat_list(_handle_data['res']['data'])
|
|
|
|
else:
|
|
|
|
_user_data = _handle_data['res']['data']
|
|
|
|
if len(_user_data) > 0:
|
|
|
|
data['user_data'] = [random.choice(_user_data)]
|
|
|
|
redis_conn.set(redis_key_api, json.dumps(data))
|
|
|
|
else:
|
|
|
|
redis_conn.delete(redis_key_api)
|
|
|
|
|
|
|
|
|
|
|
|
def get_ok_status_seat_list(_data):
|
|
|
|
seat_list = []
|
|
|
|
for s in _data:
|
|
|
|
if s['seatStatus'] == 'ok' and s['type'] in ['danren', 'zhendong', 'vip']:
|
|
|
|
seat_list.append(s)
|
|
|
|
return seat_list
|