From 0e14a86aed43871d9d0dcd14b55f36e44e7cd1bc Mon Sep 17 00:00:00 2001 From: RogerWork Date: Thu, 8 Aug 2024 18:50:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=A6=82=E4=B8=8B=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=8E=A8=E8=8D=90=20=E9=9D=9E=E4=BC=9A=E5=91=98=203.1?= =?UTF-8?q?.4=20=E8=8E=B7=E5=8F=96=E5=BD=B1=E5=8E=85=E5=BA=A7=E4=BD=8D?= =?UTF-8?q?=E5=9B=BE=203.1.6=20=E8=8E=B7=E5=8F=96=E6=94=BE=E6=98=A0?= =?UTF-8?q?=E8=AE=A1=E5=88=92=E5=88=97=E8=A1=A8=EF=BC=88=E5=A2=9E=E9=87=8F?= =?UTF-8?q?=EF=BC=89=203.1.7=20=E8=8E=B7=E5=8F=96=E6=9F=90=EF=BC=88?= =?UTF-8?q?=E5=87=A0=EF=BC=89=E4=B8=AA=E5=9C=BA=E6=AC=A1=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=203.1.8=20=E8=8E=B7=E5=8F=96=E6=9F=90=E5=9C=BA=E6=AC=A1?= =?UTF-8?q?=E5=BA=A7=E4=BD=8D=E7=8A=B6=E6=80=81=203.1.9=20=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=9F=90=E5=9C=BA=E6=AC=A1=E5=BA=A7=E4=BD=8D=E7=8A=B6?= =?UTF-8?q?=E6=80=81=EF=BC=88=E5=A2=9E=E9=87=8F=EF=BC=89=203.1.10=20?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=9F=90=EF=BC=88=E5=87=A0=EF=BC=89=E4=B8=AA?= =?UTF-8?q?=E5=9C=BA=E6=AC=A1=E5=BA=A7=E4=BD=8D=E5=94=AE=E5=8D=96=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E4=BF=A1=E6=81=AF=203.2.2=20=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=8D=95=E4=B8=AA=E5=8D=96=E5=93=81=E7=9A=84=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dspt_api/util/api/cinema_goods_pic.py | 28 +++++++++++++++++++ dspt_api/util/api/cinema_hall_seats.py | 2 +- dspt_api/util/api/cinema_plays_increment.py | 2 +- dspt_api/util/api/play_info.py | 25 +++++++++++++++++ .../util/api/play_period_changed_seats.py | 27 ++++++++++++++++++ dspt_api/util/api/play_seat_overview.py | 23 +++++++++++++++ dspt_api/util/api/play_seat_status.py | 26 +++++++++++++++++ dspt_api/util/general/handle_goods.py | 12 ++++++++ dspt_api/util/general/handle_redis.py | 18 ++++++------ dspt_api/util/suggest_params.py | 21 ++++++++++++++ 10 files changed, 173 insertions(+), 11 deletions(-) create mode 100644 dspt_api/util/api/cinema_goods_pic.py create mode 100644 dspt_api/util/api/play_info.py create mode 100644 dspt_api/util/api/play_period_changed_seats.py create mode 100644 dspt_api/util/api/play_seat_overview.py create mode 100644 dspt_api/util/api/play_seat_status.py create mode 100644 dspt_api/util/general/handle_goods.py 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