调整json处理方案

main
rogersun 2 days ago
parent a2e4c32965
commit 8dc0c24b6d
  1. 45
      ai/utils/show_process.py

@ -8,6 +8,7 @@ from django_redis import get_redis_connection
from django.db.models import Q
import re
# ai排片主流程
def show_main_process(zz_code=None, day_delta=3):
# 查看状态
@ -16,7 +17,7 @@ def show_main_process(zz_code=None, day_delta=3):
if redis_conn.exists(redis_key):
return False
# 获取影院列表
redis_conn.set(redis_key, 1, ex=60*60*20)
redis_conn.set(redis_key, 1, ex=60 * 60 * 20)
if not zz_code:
test_cinema_list = TestCinema.objects.filter(is_active=True).all()
else:
@ -41,7 +42,8 @@ def show_main_process(zz_code=None, day_delta=3):
print('message:', message)
print('tokens:', tokens)
# 获取排片数据
result_obj = result
result_obj = json.loads(result)
print('result_obj:', result_obj, type(result_obj))
# 预测排片数据
_show = result_obj['show'].replace('```', '').replace('csv', '').strip()
# 预测销售数据
@ -54,7 +56,7 @@ def show_main_process(zz_code=None, day_delta=3):
zz_code=cinema.zz_code,
show_date=show_date,
is_ai_show=True,
template = template_show,
template=template_show,
temp_date=template_date,
show=_show,
sales=_sales,
@ -69,23 +71,22 @@ def show_main_process(zz_code=None, day_delta=3):
print(e)
return True
# # 方式一
# _show = next((s for s in result.split('------') if s.startswith('\n影厅别名,影厅id')), '')
# _show = _show.strip()
# # 方式二
# if _show == '':
# _show = next((s for s in result.split('------') if s.startswith('\n```csv\n影厅别名,')), '')
# _show = _show.replace('```', '').replace('csv', '').strip()
# # 方式三
# if _show == '':
# # 正则提取中间内容
# csv_pattern = r"```csv\s*([\s\S]*?)```"
# match = re.search(csv_pattern, result)
# if match:
# _show = match.group(1)
# print('_show:', _show)
# # 获取销售额
# _sales = next((s for s in result.split('\n') if re.search(r'\d{3,6}元', s)), '')
# _sales = str(re.findall(r'\d{3,6}元', _sales)[-1])
# print('_sales:', _sales)
# _show = next((s for s in result.split('------') if s.startswith('\n影厅别名,影厅id')), '')
# _show = _show.strip()
# # 方式二
# if _show == '':
# _show = next((s for s in result.split('------') if s.startswith('\n```csv\n影厅别名,')), '')
# _show = _show.replace('```', '').replace('csv', '').strip()
# # 方式三
# if _show == '':
# # 正则提取中间内容
# csv_pattern = r"```csv\s*([\s\S]*?)```"
# match = re.search(csv_pattern, result)
# if match:
# _show = match.group(1)
# print('_show:', _show)
# # 获取销售额
# _sales = next((s for s in result.split('\n') if re.search(r'\d{3,6}元', s)), '')
# _sales = str(re.findall(r'\d{3,6}元', _sales)[-1])
# print('_sales:', _sales)

Loading…
Cancel
Save