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.
131 lines
5.7 KiB
131 lines
5.7 KiB
|
6 days ago
|
import json
|
||
|
|
import datetime
|
||
|
|
from suds.client import Client
|
||
|
|
from lib.xml_to_dict import xml_to_dict
|
||
|
|
from lib.gzip_base64 import ungzip_base64_dh2cmc
|
||
|
|
from config import global_data
|
||
|
|
from lib.redis_util import redis_set_key
|
||
|
|
from lib.transform import get_shows_transform
|
||
|
|
|
||
|
|
|
||
|
|
class GetShows:
|
||
|
|
def __init__(self, data):
|
||
|
|
self.ws_client = Client(data['basic_data']['url_ws'], cache=None)
|
||
|
|
self.ws_client.set_options(location=data['basic_data']['url_ws'])
|
||
|
|
self.user_name = data['basic_data']['user_name'] # 固定写死的参数
|
||
|
|
self.password = data['basic_data']['password'] # 固定写死的参数
|
||
|
|
self.cinema_id = data['basic_data']['cinema_id']
|
||
|
|
self.show_date = None
|
||
|
|
|
||
|
|
def prepare(self, show_date):
|
||
|
|
if show_date == "TODAY":
|
||
|
|
self.show_date = datetime.datetime.strftime(datetime.datetime.today(), '%Y-%m-%d')
|
||
|
|
else:
|
||
|
|
self.show_date = show_date
|
||
|
|
|
||
|
|
def request(self, show_date):
|
||
|
|
# 准备请求数据
|
||
|
|
self.prepare(show_date)
|
||
|
|
|
||
|
|
if self.show_date is None:
|
||
|
|
return False
|
||
|
|
|
||
|
|
print('-' * 100 + '\n' + '请求getShows接口')
|
||
|
|
data = {'UserName': self.user_name,
|
||
|
|
'Password': self.password,
|
||
|
|
'CinemaId': self.cinema_id,
|
||
|
|
'ShowDate': show_date,
|
||
|
|
'BookingFlg': 'N' # BookingFlg
|
||
|
|
}
|
||
|
|
print(json.dumps(data))
|
||
|
|
result_xml = self.ws_client.service.getShows(**data)
|
||
|
|
|
||
|
|
# 处理返回数据格式
|
||
|
|
if 'xml' not in result_xml:
|
||
|
|
print(f"-- gzip加密结果 --\n{result_xml}")
|
||
|
|
result_xml = ungzip_base64_dh2cmc(result_xml)
|
||
|
|
|
||
|
|
result_dict = xml_to_dict(result_xml)
|
||
|
|
result_json = json.dumps(result_dict, ensure_ascii=False)
|
||
|
|
print("-- Json结果 --\n", result_json)
|
||
|
|
|
||
|
|
# 返回结果写缓存
|
||
|
|
redis_set_key('xml_get_shows', json.dumps(get_shows_transform(result_dict)))
|
||
|
|
|
||
|
|
# 处理返回数据
|
||
|
|
self.handle()
|
||
|
|
|
||
|
|
# 返回数据用于记录测试结果
|
||
|
|
return data, result_xml, result_dict
|
||
|
|
|
||
|
|
def handle(self):
|
||
|
|
# show_list = []
|
||
|
|
# film_list = self.response_data['get_shows']['film']
|
||
|
|
# if isinstance(film_list, list):
|
||
|
|
# for film in film_list:
|
||
|
|
# # print(film)
|
||
|
|
# dt = film['shows']['show']['date'] + ' ' + (
|
||
|
|
# film['shows']['show']['time'] if len(film['shows']['show']['time']) == 4 else '0' +
|
||
|
|
# film['shows']['show'][
|
||
|
|
# 'time'])
|
||
|
|
# if datetime.datetime.strptime(dt, '%Y-%m-%d %H%M') >= datetime.datetime.now():
|
||
|
|
# f = film['shows']
|
||
|
|
# d = {'film_id': film['id'],
|
||
|
|
# 'show_code': f['show']['performId'],
|
||
|
|
# 'show_date': f['show']['date'],
|
||
|
|
# 'show_time': f['show']['time'],
|
||
|
|
# 'hall_id': f['show']['hId'],
|
||
|
|
# 'market_price': f['show']['marketPrice'],
|
||
|
|
# 'low_price': f['show']['minimunPrice'],
|
||
|
|
# 'service_fee': f['show']['serviceFee'],
|
||
|
|
# 'title': film['title'],
|
||
|
|
# 'hall': f['show']['hall']}
|
||
|
|
# show_list.append(d)
|
||
|
|
# else:
|
||
|
|
# film = film_list
|
||
|
|
# dt = film['shows']['show']['date'] + ' ' + (
|
||
|
|
# film['shows']['show']['time'] if len(film['shows']['show']['time']) == 4 else '0' +
|
||
|
|
# film['shows'][
|
||
|
|
# 'show'][
|
||
|
|
# 'time'])
|
||
|
|
# if datetime.datetime.strptime(dt, '%Y-%m-%d %H%M') >= datetime.datetime.now():
|
||
|
|
# f = film['shows']
|
||
|
|
# d = {'film_id': film['id'],
|
||
|
|
# 'show_code': f['show']['performId'],
|
||
|
|
# 'show_date': f['show']['date'],
|
||
|
|
# 'show_time': f['show']['time'],
|
||
|
|
# 'hall_id': f['show']['hId'],
|
||
|
|
# 'market_price': f['show']['marketPrice'],
|
||
|
|
# 'low_price': f['show']['minimunPrice'],
|
||
|
|
# 'service_fee': f['show']['serviceFee'],
|
||
|
|
# 'title': film['title'],
|
||
|
|
# 'hall': f['show']['hall']}
|
||
|
|
# show_list.append(d)
|
||
|
|
# self.user_data['show_list'] = show_list
|
||
|
|
# self.print_shows()
|
||
|
|
pass
|
||
|
|
|
||
|
|
# def print_shows(self):
|
||
|
|
# title_list = []
|
||
|
|
# show_datetime_list = []
|
||
|
|
# show_code_list = []
|
||
|
|
# for s in self.user_data['show_list']:
|
||
|
|
# title_list.append(s['title'])
|
||
|
|
# st = s['show_time']
|
||
|
|
# stime = f'{st[0:2]}:{st[2:]}' if len(st) == 4 else f'0{st[0]}:{st[1:]}'
|
||
|
|
# show_datetime_list.append(f"{s['show_date']} {stime}")
|
||
|
|
# show_code_list.append(s['show_code'])
|
||
|
|
# print(f"{s['title']} - {s['show_date']} {stime} - {s['show_code']}")
|
||
|
|
# title_str = "', '".join(title_list)
|
||
|
|
# print(f"'{title_str}'")
|
||
|
|
# show_datetime_str = "', '".join(show_datetime_list)
|
||
|
|
# print(f"'{show_datetime_str}'")
|
||
|
|
# show_code_str = "', '".join(show_code_list)
|
||
|
|
# print(f"'{show_code_str}'")
|
||
|
|
# print(f"一共 {len(show_code_list)} 场")
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
api = GetShows(global_data)
|
||
|
|
api.request('TODAY')
|