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.
31 lines
1.3 KiB
31 lines
1.3 KiB
from django_redis import get_redis_connection |
|
import json |
|
import xmltodict |
|
|
|
|
|
# 封装方法处理从redis中获取接口数据 |
|
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)) |
|
resp_data = [] |
|
resp_result = 0 |
|
if cinema_halls_data['format'] == 'json': |
|
resp = json.loads(cinema_halls_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']) |
|
print('xml-response', resp) |
|
resp_result = resp['root']['status'] |
|
if str(resp_result) == '1': |
|
resp_data = resp['root']['data']['item'] |
|
if str(resp_result) != '1': |
|
return False, '请检查接口返回值或手动输入参数:' |
|
if len(resp_data) == 0: |
|
return False, '接口返回数据为空,请手动输入参数:' |
|
return True, resp_data |
|
return False, '请手动输入参数,或先请求接口:'
|
|
|