From 5c5952ee49a426257b2f8822e202b35cd98f74d3 Mon Sep 17 00:00:00 2001 From: rogersun Date: Fri, 17 Jul 2026 17:00:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=94=E5=9B=9E=E7=9A=84=E6=8E=92=E7=89=87?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E4=BD=BF=E7=94=A8json=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ai/utils/basic_func.py | 10 +++++++++- ai/utils/show_process.py | 25 +++++++++++++++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/ai/utils/basic_func.py b/ai/utils/basic_func.py index 0ae6513..629cbeb 100644 --- a/ai/utils/basic_func.py +++ b/ai/utils/basic_func.py @@ -196,6 +196,14 @@ def data_cleansing(data: str): return data.replace(',', ',').replace('影厅 id', '影厅id').replace('本地影片 id', '本地影片id').replace(', ', ',') +def json_to_csv(data:list): + csv_list = ['影厅别名,影厅id,影片别名,本地影片id,语言,放映日期,开始时间,结束时间,片长,场间', ] + for d in data: + csv_list.append( + f"{d['hall_name']},{d['hall_id']},{d['movie_alias']},{d['movie_id']},{d['language']},{d['show_date']},{d['start']},{d['end']},{d['length']},{d['duration']}") + return '\n'.join(csv_list) + + # 获取排片数据的起始和结束日期 def get_report_date(): start_date = datetime.datetime.strftime( @@ -218,7 +226,7 @@ def is_summer(target: str, start='06-11', end='08-31') -> bool: # 根据输入的两个日期,判端是否需要增减场次 -def add_reduce_rule(template:bool, target: bool) -> str: +def add_reduce_rule(template: bool, target: bool) -> str: if template is True and target is False: return 'decrease' elif template is False and target is True: diff --git a/ai/utils/show_process.py b/ai/utils/show_process.py index 26dfdd2..11befe4 100644 --- a/ai/utils/show_process.py +++ b/ai/utils/show_process.py @@ -60,11 +60,15 @@ def show_main_process(zz_code=None, day_delta=None): else: result_obj = json.loads(result.strip()) + show_result = result_obj['show'] # 预测排片数据 - _show = result_obj['show'].replace('```', '').replace('csv', '').strip() + if isinstance(show_result, list): + show = json_to_csv(show_result) + else: + show = data_cleansing(show_result.replace('```', '').replace('csv', '').strip()) # 预测销售数据 - _sales = str(result_obj['income']).strip() + sales = str(result_obj['income']).strip() # 处理返回结果 try: @@ -78,8 +82,8 @@ def show_main_process(zz_code=None, day_delta=None): template=template_show, temp_date=template_date, target=target_show, - show=data_cleansing(_show), - sales=_sales, + show=show, + sales=sales, prompt=prompt, result=result, message=message, @@ -124,10 +128,15 @@ def show_manual_process(zz_code: str, show_date: str, prompt: str): result_obj = json.loads(result.strip()) # 预测排片数据 - _show = result_obj['show'].replace('```', '').replace('csv', '').strip() + show_result = result_obj['show'] + # 预测排片数据 + if isinstance(show_result, list): + show = json_to_csv(show_result) + else: + show = data_cleansing(show_result.replace('```', '').replace('csv', '').strip()) # 预测销售数据 - _sales = str(result_obj['income']).strip() + sales = str(result_obj['income']).strip() # 处理返回结果 try: @@ -141,8 +150,8 @@ def show_manual_process(zz_code: str, show_date: str, prompt: str): template=template_show, temp_date=template_date, target=target_show, - show=data_cleansing(_show), - sales=_sales, + show=show, + sales=sales, prompt=prompt, result=result, message=message,