diff --git a/dspt_api/util/api/cinema_goods_pic.py b/dspt_api/util/api/cinema_goods_pic.py new file mode 100644 index 0000000..cd3b4cb --- /dev/null +++ b/dspt_api/util/api/cinema_goods_pic.py @@ -0,0 +1,28 @@ +from dspt_api.util.general.handle_redis import get_data_from_redis +from dspt_api.util.general.handle_goods import get_goods_list +import random + + +class ApiCinemaGoodsPic(object): + def __init__(self, **kwargs): + self.member_type = kwargs.get('member_type') + self.api = kwargs.get('api') + self.ip = kwargs.get('ip') + + def get_suggestion(self): + # play_id play_update_time + request_api = {'name': '3.2.1 获取卖品列表', 'path': 'cinema/goods'} + redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}' + result, _format, redis_data = get_data_from_redis(redis_key_api) + if result: + goods_list = get_goods_list(redis_data, _format) + goods = random.choice(goods_list) + goods_id = goods['id'] + goods_type = goods['type'] + return [{'param': 'goods_id', 'value': goods_id, 'is_checked': True}, + {'param': 'type', 'value': goods_type, 'is_checked': True}] + else: + # 返回推荐参数应该包含参数名,参数值,和是否勾选的状态 + return [ + {'param': 'goods_id', 'value': redis_data + request_api["name"], 'is_checked': True}, + {'param': 'type', 'value': redis_data + request_api["name"], 'is_checked': True}] diff --git a/dspt_api/util/api/cinema_hall_seats.py b/dspt_api/util/api/cinema_hall_seats.py index 1c27995..6e2826f 100644 --- a/dspt_api/util/api/cinema_hall_seats.py +++ b/dspt_api/util/api/cinema_hall_seats.py @@ -12,7 +12,7 @@ class ApiCinemaHallSeats: # hall_id request_api = {'name': '3.1.3 获取影厅列表', 'path': 'cinema/halls'} redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}' - result, redis_data = get_data_from_redis(redis_key_api) + result, _format, redis_data = get_data_from_redis(redis_key_api) if result: hall_data = random.choice(redis_data) hall_id = hall_data['id'] diff --git a/dspt_api/util/api/cinema_plays_increment.py b/dspt_api/util/api/cinema_plays_increment.py index 25288cc..7f05786 100644 --- a/dspt_api/util/api/cinema_plays_increment.py +++ b/dspt_api/util/api/cinema_plays_increment.py @@ -12,7 +12,7 @@ class ApiCinemaPlaysIncrement: # start request_api = {'name': '3.1.6 获取放映计划列表(增量)', 'path': 'cinema/plays-increment'} redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}' - result, redis_data = get_data_from_redis(redis_key_api) + result, _format, redis_data = get_data_from_redis(redis_key_api) # 生成默认值 start = redis_data['nextSyncStartTime'] if result else datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d') + ' 06:00:00' diff --git a/dspt_api/util/api/play_info.py b/dspt_api/util/api/play_info.py new file mode 100644 index 0000000..7d42653 --- /dev/null +++ b/dspt_api/util/api/play_info.py @@ -0,0 +1,25 @@ +from dspt_api.util.general.handle_redis import get_data_from_redis +import random + + +class ApiPlayInfo: + def __init__(self, **kwargs): + self.member_type = kwargs.get('member_type') + self.api = kwargs.get('api') + self.ip = kwargs.get('ip') + + def get_suggestion(self): + # hall_id + request_api = {'name': '3.1.5 获取放映计划列表', 'path': 'cinema/plays'} + redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}' + result, _format, redis_data = get_data_from_redis(redis_key_api) + if result: + play_data = random.choice(redis_data) + play_id = play_data['id'] + return [{'param': 'play_id', 'value': play_id, 'is_checked': True}] + else: + # 返回推荐参数应该包含参数名,参数值,和是否勾选的状态 + return [ + {'param': 'play_id', 'value': redis_data + request_api["name"], 'is_checked': True}] + + diff --git a/dspt_api/util/api/play_period_changed_seats.py b/dspt_api/util/api/play_period_changed_seats.py new file mode 100644 index 0000000..44b55e5 --- /dev/null +++ b/dspt_api/util/api/play_period_changed_seats.py @@ -0,0 +1,27 @@ +from dspt_api.util.general.handle_redis import get_data_from_redis +import random +import datetime + + +class ApiPlayPeriodChangedSeats: + def __init__(self, **kwargs): + self.member_type = kwargs.get('member_type') + self.api = kwargs.get('api') + self.ip = kwargs.get('ip') + + def get_suggestion(self): + # play_id play_update_time + request_api = {'name': '3.1.5 获取放映计划列表', 'path': 'cinema/plays'} + redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}' + result, _format, redis_data = get_data_from_redis(redis_key_api) + if result: + play_data = random.choice(redis_data) + play_id = play_data['id'] + start = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d') + ' 06:00:00' + return [{'param': 'play_id', 'value': play_id, 'is_checked': True}, + {'param': 'start', 'value': start, 'is_checked': True}] + else: + # 返回推荐参数应该包含参数名,参数值,和是否勾选的状态 + return [ + {'param': 'play_id', 'value': redis_data + request_api["name"], 'is_checked': True}, + {'param': 'start', 'value': redis_data + request_api["name"], 'is_checked': True}] diff --git a/dspt_api/util/api/play_seat_overview.py b/dspt_api/util/api/play_seat_overview.py new file mode 100644 index 0000000..566b3b3 --- /dev/null +++ b/dspt_api/util/api/play_seat_overview.py @@ -0,0 +1,23 @@ +from dspt_api.util.general.handle_redis import get_data_from_redis +import random + + +class ApiPlaySeatOverview: + def __init__(self, **kwargs): + self.member_type = kwargs.get('member_type') + self.api = kwargs.get('api') + self.ip = kwargs.get('ip') + + def get_suggestion(self): + # play_id play_update_time + request_api = {'name': '3.1.5 获取放映计划列表', 'path': 'cinema/plays'} + redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}' + result, _format, redis_data = get_data_from_redis(redis_key_api) + if result: + play_data = random.choice(redis_data) + play_id = play_data['id'] + return [{'param': 'play_id', 'value': play_id, 'is_checked': True}] + else: + # 返回推荐参数应该包含参数名,参数值,和是否勾选的状态 + return [ + {'param': 'play_id', 'value': redis_data + request_api["name"], 'is_checked': True}] diff --git a/dspt_api/util/api/play_seat_status.py b/dspt_api/util/api/play_seat_status.py new file mode 100644 index 0000000..388b525 --- /dev/null +++ b/dspt_api/util/api/play_seat_status.py @@ -0,0 +1,26 @@ +from dspt_api.util.general.handle_redis import get_data_from_redis +import random + + +class ApiPlaySeatStatus: + def __init__(self, **kwargs): + self.member_type = kwargs.get('member_type') + self.api = kwargs.get('api') + self.ip = kwargs.get('ip') + + def get_suggestion(self): + # play_id play_update_time + request_api = {'name': '3.1.5 获取放映计划列表', 'path': 'cinema/plays'} + redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}' + result, _format, redis_data = get_data_from_redis(redis_key_api) + if result: + play_data = random.choice(redis_data) + play_id = play_data['id'] + play_update_time = play_data['cineUpdateTime'] + return [{'param': 'play_id', 'value': play_id, 'is_checked': True}, + {'param': 'play_update_time', 'value': play_update_time, 'is_checked': True}] + else: + # 返回推荐参数应该包含参数名,参数值,和是否勾选的状态 + return [ + {'param': 'play_id', 'value': redis_data + request_api["name"], 'is_checked': True}, + {'param': 'play_update_time', 'value': redis_data + request_api["name"], 'is_checked': True}] diff --git a/dspt_api/util/general/handle_goods.py b/dspt_api/util/general/handle_goods.py new file mode 100644 index 0000000..036a865 --- /dev/null +++ b/dspt_api/util/general/handle_goods.py @@ -0,0 +1,12 @@ +def get_goods_list(goods_resp, _format): + goods_list = [] + if _format == 'json': + for goods_cate in goods_resp: + goods_list = goods_list + goods_cate['goods'] + if _format == 'xml': + for goods_cate in goods_resp['cate']: + if isinstance(goods_cate['goods']['item'], dict): + goods_list.append(goods_cate['goods']['item']) + else: + goods_list = goods_list + goods_cate['goods']['item'] + return goods_list diff --git a/dspt_api/util/general/handle_redis.py b/dspt_api/util/general/handle_redis.py index 898b5a9..f6178bd 100644 --- a/dspt_api/util/general/handle_redis.py +++ b/dspt_api/util/general/handle_redis.py @@ -8,24 +8,24 @@ def get_data_from_redis(redis_key): # 初始化redis redis_conn = get_redis_connection() if redis_conn.exists(redis_key): - cinema_halls_data = json.loads(redis_conn.get(redis_key)) + redis_data = json.loads(redis_conn.get(redis_key)) resp_data = [] resp_result = 0 - if cinema_halls_data['format'] == 'json': - resp = json.loads(cinema_halls_data['response_data']) + if redis_data['format'] == 'json': + resp = json.loads(redis_data['response_data']) print('json-response', resp) resp_result = resp['res']['status'] if str(resp_result) == '1': resp_data = resp['res']['data'] - if cinema_halls_data['format'] == 'xml': - resp = xmltodict.parse(cinema_halls_data['response_data']) + if redis_data['format'] == 'xml': + resp = xmltodict.parse(redis_data['response_data']) print('xml-response', resp) resp_result = resp['root']['status'] if str(resp_result) == '1': resp_data = resp['root']['data'].get('item', resp['root']['data']) if str(resp_result) != '1': - return False, '请检查接口返回值或手动输入参数:' + return False, redis_data['format'], '请检查接口返回值或手动输入参数:' if len(resp_data) == 0: - return False, '接口返回数据为空,请手动输入参数:' - return True, resp_data - return False, '请手动输入参数,或先请求接口:' + return False, redis_data['format'], '接口返回数据为空,请手动输入参数:' + return True, redis_data['format'], resp_data + return False, 'json', '请手动输入参数,或先请求接口:' diff --git a/dspt_api/util/suggest_params.py b/dspt_api/util/suggest_params.py index b57d8a0..42b3c44 100644 --- a/dspt_api/util/suggest_params.py +++ b/dspt_api/util/suggest_params.py @@ -1,5 +1,10 @@ from dspt_api.util.api.cinema_hall_seats import ApiCinemaHallSeats from dspt_api.util.api.cinema_plays_increment import ApiCinemaPlaysIncrement +from dspt_api.util.api.play_info import ApiPlayInfo +from dspt_api.util.api.play_seat_status import ApiPlaySeatStatus +from dspt_api.util.api.play_period_changed_seats import ApiPlayPeriodChangedSeats +from dspt_api.util.api.play_seat_overview import ApiPlaySeatOverview +from dspt_api.util.api.cinema_goods_pic import ApiCinemaGoodsPic # 通过api来匹配不同的接口文件获取推荐 @@ -7,10 +12,26 @@ from dspt_api.util.api.cinema_plays_increment import ApiCinemaPlaysIncrement def suggest_params(member_type, api, ip): data = {'member_type': member_type, 'api': api, 'ip': ip} params = [] + # 非会员 if api == 'cinema/hall-seats' and member_type == 'nonmember': print('cinema/hall-seats') params = ApiCinemaHallSeats(**data).get_suggestion() if api == 'cinema/plays-increment' and member_type == 'nonmember': print('cinema/plays-increment') params = ApiCinemaPlaysIncrement(**data).get_suggestion() + if api == 'play/info' and member_type == 'nonmember': + print('play/info') + params = ApiPlayInfo(**data).get_suggestion() + if api == 'play/seat-status' and member_type == 'nonmember': + print('play/seat-status') + params = ApiPlaySeatStatus(**data).get_suggestion() + if api == 'play/period-changed-seats' and member_type == 'nonmember': + print('play/period-changed-seats') + params = ApiPlayPeriodChangedSeats(**data).get_suggestion() + if api == 'play/seat-overview' and member_type == 'nonmember': + print('play/seat-overview') + params = ApiPlaySeatOverview(**data).get_suggestion() + if api == 'cinema/goods-pic' and member_type == 'nonmember': + print('cinema/goods-pic') + params = ApiCinemaGoodsPic(**data).get_suggestion() return params