From 9e1acfae20895a59dad50b55a24b53b91159cd06 Mon Sep 17 00:00:00 2001 From: RogerWork Date: Thu, 8 Aug 2024 11:51:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E7=BC=BA=E5=A4=B1=E7=9A=84?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dspt_api/util/api/cinema_plays_increment.py | 19 +++++++++++++++++++ dspt_api/util/general/handle_redis.py | 2 +- dspt_api/util/suggest_params.py | 4 ++++ reqirement.txt | Bin 2728 -> 3022 bytes 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 dspt_api/util/api/cinema_plays_increment.py diff --git a/dspt_api/util/api/cinema_plays_increment.py b/dspt_api/util/api/cinema_plays_increment.py new file mode 100644 index 0000000..25288cc --- /dev/null +++ b/dspt_api/util/api/cinema_plays_increment.py @@ -0,0 +1,19 @@ +from dspt_api.util.general.handle_redis import get_data_from_redis +import datetime + + +class ApiCinemaPlaysIncrement: + 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): + # 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) + # 生成默认值 + start = redis_data['nextSyncStartTime'] if result else datetime.datetime.strftime(datetime.datetime.now(), + '%Y-%m-%d') + ' 06:00:00' + return [{'param': 'start', 'value': start, 'is_checked': True}] diff --git a/dspt_api/util/general/handle_redis.py b/dspt_api/util/general/handle_redis.py index eb7b5f8..898b5a9 100644 --- a/dspt_api/util/general/handle_redis.py +++ b/dspt_api/util/general/handle_redis.py @@ -22,7 +22,7 @@ def get_data_from_redis(redis_key): print('xml-response', resp) resp_result = resp['root']['status'] if str(resp_result) == '1': - resp_data = resp['root']['data']['item'] + resp_data = resp['root']['data'].get('item', resp['root']['data']) if str(resp_result) != '1': return False, '请检查接口返回值或手动输入参数:' if len(resp_data) == 0: diff --git a/dspt_api/util/suggest_params.py b/dspt_api/util/suggest_params.py index f259ac0..b57d8a0 100644 --- a/dspt_api/util/suggest_params.py +++ b/dspt_api/util/suggest_params.py @@ -1,4 +1,5 @@ from dspt_api.util.api.cinema_hall_seats import ApiCinemaHallSeats +from dspt_api.util.api.cinema_plays_increment import ApiCinemaPlaysIncrement # 通过api来匹配不同的接口文件获取推荐 @@ -9,4 +10,7 @@ def suggest_params(member_type, api, ip): 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() return params diff --git a/reqirement.txt b/reqirement.txt index 4596235260d94515a4dbdf6412e07ba1ca62a69d..73b0d5fb2ea704e93edeabfa0db1872fac4bb1de 100644 GIT binary patch delta 262 zcmZ1>dQN`9PS%Pz+XK0F*TYV#Cd*tjn1uuVLpB&j%_=WyoVF zgBt--WH|XEyRLWu&>4{ojtssGK44jpR-o+U@9djJ^MFoB145WHL6#eDp3gCxQ92Q5 tWHLhrSTYA_IKpnD$+}#DvK0)uKo@~rmIBnC3}k^^54M)UcycM1F#z6;G{^t| delta 40 ycmV+@0N4M{7pN7G9