完成如下接口推荐

非会员
3.1.4 获取影厅座位图
3.1.6 获取放映计划列表(增量)
3.1.7 获取某(几)个场次信息
3.1.8 获取某场次座位状态
3.1.9 获取某场次座位状态(增量)
3.1.10 获取某(几)个场次座位售卖统计信息
3.2.2 获取单个卖品的图片信息
main
RogerWork 3 months ago
parent 9e1acfae20
commit 0e14a86aed
  1. 28
      dspt_api/util/api/cinema_goods_pic.py
  2. 2
      dspt_api/util/api/cinema_hall_seats.py
  3. 2
      dspt_api/util/api/cinema_plays_increment.py
  4. 25
      dspt_api/util/api/play_info.py
  5. 27
      dspt_api/util/api/play_period_changed_seats.py
  6. 23
      dspt_api/util/api/play_seat_overview.py
  7. 26
      dspt_api/util/api/play_seat_status.py
  8. 12
      dspt_api/util/general/handle_goods.py
  9. 18
      dspt_api/util/general/handle_redis.py
  10. 21
      dspt_api/util/suggest_params.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}]

@ -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']

@ -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'

@ -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}]

@ -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}]

@ -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}]

@ -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}]

@ -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

@ -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', '请手动输入参数,或先请求接口:'

@ -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

Loading…
Cancel
Save