调整json处理方案

main
rogersun 3 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 from django.db.models import Q
import re import re
# ai排片主流程 # ai排片主流程
def show_main_process(zz_code=None, day_delta=3): 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): if redis_conn.exists(redis_key):
return False 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: if not zz_code:
test_cinema_list = TestCinema.objects.filter(is_active=True).all() test_cinema_list = TestCinema.objects.filter(is_active=True).all()
else: else:
@ -41,7 +42,8 @@ def show_main_process(zz_code=None, day_delta=3):
print('message:', message) print('message:', message)
print('tokens:', tokens) 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() _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, zz_code=cinema.zz_code,
show_date=show_date, show_date=show_date,
is_ai_show=True, is_ai_show=True,
template = template_show, template=template_show,
temp_date=template_date, temp_date=template_date,
show=_show, show=_show,
sales=_sales, sales=_sales,
@ -69,23 +71,22 @@ def show_main_process(zz_code=None, day_delta=3):
print(e) print(e)
return True return True
# # 方式一 # # 方式一
# _show = next((s for s in result.split('------') if s.startswith('\n影厅别名,影厅id')), '') # _show = next((s for s in result.split('------') if s.startswith('\n影厅别名,影厅id')), '')
# _show = _show.strip() # _show = _show.strip()
# # 方式二 # # 方式二
# if _show == '': # if _show == '':
# _show = next((s for s in result.split('------') if s.startswith('\n```csv\n影厅别名,')), '') # _show = next((s for s in result.split('------') if s.startswith('\n```csv\n影厅别名,')), '')
# _show = _show.replace('```', '').replace('csv', '').strip() # _show = _show.replace('```', '').replace('csv', '').strip()
# # 方式三 # # 方式三
# if _show == '': # if _show == '':
# # 正则提取中间内容 # # 正则提取中间内容
# csv_pattern = r"```csv\s*([\s\S]*?)```" # csv_pattern = r"```csv\s*([\s\S]*?)```"
# match = re.search(csv_pattern, result) # match = re.search(csv_pattern, result)
# if match: # if match:
# _show = match.group(1) # _show = match.group(1)
# print('_show:', _show) # print('_show:', _show)
# # 获取销售额 # # 获取销售额
# _sales = next((s for s in result.split('\n') if re.search(r'\d{3,6}元', s)), '') # _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]) # _sales = str(re.findall(r'\d{3,6}元', _sales)[-1])
# print('_sales:', _sales) # print('_sales:', _sales)

Loading…
Cancel
Save