You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
2.1 KiB
56 lines
2.1 KiB
3 months ago
|
import random
|
||
|
import json
|
||
|
import time
|
||
|
from django_redis import get_redis_connection
|
||
|
|
||
3 months ago
|
RANDOM_DATA_API_LIST = ['cinema/plays', 'play/seat-status', 'cinema/goods', 'ecard/ecard-levels']
|
||
3 months ago
|
|
||
3 months ago
|
|
||
3 months ago
|
def random_params(_user_info, _handle_data):
|
||
3 months ago
|
if _user_info["api"] in RANDOM_DATA_API_LIST:
|
||
3 months ago
|
if str(_handle_data['res']['status']) == '0':
|
||
|
return False
|
||
3 months ago
|
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"],
|
||
3 months ago
|
'timestamp': int(time.time() * 1000),
|
||
3 months ago
|
}
|
||
|
if _user_info["api"] == 'play/seat-status':
|
||
|
_user_data = get_ok_status_seat_list(_handle_data['res']['data'])
|
||
3 months ago
|
if _user_info["api"] == 'ecard/ecard-levels':
|
||
|
_user_data = _handle_data['res']['data']['ecardLevelData']
|
||
3 months ago
|
if _user_info["api"] == 'cinema/goods':
|
||
|
print('random_params', _handle_data['res']['data'])
|
||
|
_user_data = [random_goods(_handle_data['res']['data'])]
|
||
3 months ago
|
else:
|
||
|
_user_data = _handle_data['res']['data']
|
||
|
if len(_user_data) > 0:
|
||
3 months ago
|
if _user_info["api"] in ('play/seat-status', 'cinema/goods'):
|
||
3 months ago
|
data['user_data'] = [[random.choice(_user_data)]]
|
||
|
else:
|
||
|
data['user_data'] = [random.choice(_user_data)]
|
||
3 months ago
|
redis_conn.set(redis_key_api, json.dumps(data), 10 * 60 * 60)
|
||
3 months ago
|
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
|
||
3 months ago
|
|
||
|
|
||
|
def random_goods(_data):
|
||
|
goods = random.choice(_data)
|
||
|
n = 1
|
||
|
while goods['type'] == 'package' and goods['packageType'] == '2' and n < 10:
|
||
|
goods = random.choice(_data)
|
||
|
n += 1
|
||
|
return goods
|