diff --git a/ai/urls.py b/ai/urls.py index 59818d8..1b6d93e 100644 --- a/ai/urls.py +++ b/ai/urls.py @@ -27,4 +27,5 @@ urlpatterns = [ path('new_movie', insert_new_movie), path('test', manual_test), path('test_date', get_test_date), + path('get_prompt', get_prompt), ] diff --git a/ai/utils/show_database.py b/ai/utils/show_database.py index 92bb3db..04fb473 100644 --- a/ai/utils/show_database.py +++ b/ai/utils/show_database.py @@ -58,15 +58,23 @@ class GetData: # 获取指定日期的可用于排片的影片 def get_handle_movie(self, date): - start_datetime = datetime.datetime.strptime(date, '%Y-%m-%d') + datetime.timedelta(hours=29, minutes=59, - seconds=59) - end_datetime = datetime.datetime.strptime(date, '%Y-%m-%d') + datetime.timedelta(hours=6) + if get_runtime_val('real_target') == '0': + start_datetime = datetime.datetime.today().replace(hour=6, minute=0,second=0,microsecond=0) + end_datetime = datetime.datetime.strptime(date, '%Y-%m-%d') + datetime.timedelta(hours=29, minutes=59, + seconds=59) + else: + start_datetime = datetime.datetime.strptime(date, '%Y-%m-%d') + datetime.timedelta(hours=29, minutes=59, + seconds=59) + end_datetime = datetime.datetime.strptime(date, '%Y-%m-%d') + datetime.timedelta(hours=6) + + print('get_handle_movie-start_datetime', datetime.datetime.strftime(start_datetime, '%Y-%m-%d %H:%M:%S')) + print('get_handle_movie-end_datetime', datetime.datetime.strftime(end_datetime, '%Y-%m-%d %H:%M:%S')) bl_bool, bl_str, bl_list = get_black_list(self.zz_code) if bl_bool: if get_runtime_val('real_target') == '0': sql = GET_HANDLE_MOVIE_TEST + bl_str + ');' - self.cur.execute(sql, (end_datetime, start_datetime, *bl_list)) - print(self.cur.mogrify(sql, (end_datetime, start_datetime, *bl_list))) + self.cur.execute(sql, (start_datetime, end_datetime, *bl_list)) + print(self.cur.mogrify(sql, (start_datetime, end_datetime, *bl_list))) else: sql = GET_HANDLE_MOVIE + bl_str + ');' self.cur.execute(sql, (start_datetime, end_datetime, *bl_list)) @@ -74,8 +82,8 @@ class GetData: else: if get_runtime_val('real_target') == '0': sql = GET_HANDLE_MOVIE_TEST + bl_str + ');' - self.cur.execute(sql, (end_datetime, start_datetime)) - print(self.cur.mogrify(sql, (end_datetime, start_datetime))) + self.cur.execute(sql, (start_datetime, end_datetime)) + print(self.cur.mogrify(sql, (start_datetime, end_datetime))) else: sql = GET_HANDLE_MOVIE + bl_str + ');' self.cur.execute(sql, (start_datetime, end_datetime)) diff --git a/ai/utils/show_func.py b/ai/utils/show_func.py index 9dbb96d..725f53f 100644 --- a/ai/utils/show_func.py +++ b/ai/utils/show_func.py @@ -213,5 +213,5 @@ def get_movie_guidance(cinema, show_date): def get_test_date_from_db(cinema_code: str, show_date: str) -> list: test_data = AiShow.objects.filter( - Q(zz_code=cinema_code) & Q(show_date=show_date) & Q(is_ai_show=True) & Q(is_manual_test=True)).all() + Q(zz_code=cinema_code) & Q(show_date>=show_date) & Q(is_ai_show=True) & Q(is_manual_test=True)).all() return [test.prompt_version for test in test_data] diff --git a/ai/utils/show_process.py b/ai/utils/show_process.py index e603ec7..351936d 100644 --- a/ai/utils/show_process.py +++ b/ai/utils/show_process.py @@ -150,22 +150,21 @@ def show_manual_process(zz_code: str, show_date: str, prompt: str): return e return result -# # 方式一 -# _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) + +def get_prompt_process(zz_code=None, show_date=None): + print('zz_code:', zz_code) + print('show_date:', show_date) + if zz_code == '' or show_date == '' : + return '请检查影院编码和排片日期' + # 获取影院 + cinema = TestCinema.objects.filter(Q(zz_code=zz_code) & Q(is_active=True)).first() + # 获取提示词版本 + prompt_ver = PromptTemplate.objects.filter( + Q(del_flag=False) & Q(prompt_type='version') & Q(prompt_key='ShowPromptVersion')).first().prompt_val + # 开始处理提示词 + # 按照影院生成排片 + print(cinema.name) + show_ai = ShowAI(cinema, show_date) + prompt = show_ai.general_prompt() + return prompt + diff --git a/ai/views.py b/ai/views.py index c50f234..28a05e6 100644 --- a/ai/views.py +++ b/ai/views.py @@ -5,7 +5,7 @@ from django.views.decorators.csrf import csrf_exempt import json from ai.models import * import time -from ai.utils.show_process import show_main_process, show_manual_process +from ai.utils.show_process import show_main_process, show_manual_process, get_prompt_process from ai.utils.show_func import * from ai.utils.basic_func import * @@ -206,3 +206,16 @@ def get_test_date(request): } print(result_dict) return JsonResponse(result_dict, json_dumps_params={'ensure_ascii': False}) + + +@csrf_exempt +def get_prompt(request): + cinema_code = request.GET.get('cinema_code') + show_date = request.GET.get('show_date') + result_dict = { + 'status': 'success', + 'message': '成功', + 'data': get_prompt_process(cinema_code, show_date) + } + print(result_dict) + return JsonResponse(result_dict, json_dumps_params={'ensure_ascii': False}) \ No newline at end of file diff --git a/update/utils/get_version.py b/update/utils/get_version.py index 5868922..3f1ef17 100644 --- a/update/utils/get_version.py +++ b/update/utils/get_version.py @@ -26,7 +26,9 @@ class GetVersion(object): data = { 'ip': cinema_obj.ip, 'db_user': cinema_obj.db_user, - 'db_pwd': cinema_obj.db_pwd + 'db_pwd': cinema_obj.db_pwd, + 'db_name': cinema_obj.db_name, + 'url': cinema_obj.url, } self.queue.put(data) cpu_num = cpu_count() - 1 if cpu_count() > 1 else 1 @@ -52,14 +54,19 @@ class GetVersion(object): return else: cinema_config = q.get() + sql_str = "SELECT cs.*, cv.server_version, cv.client_version FROM cinema_set cs LEFT JOIN cinema_version cv ON 1=1;" + ip = cinema_config.get('ip') db_config = { - 'host': cinema_config.get('ip'), + 'host': ip, 'user': cinema_config.get('db_user'), 'password': cinema_config.get('db_pwd'), 'database': cinema_config.get('db_name'), 'connect_timeout': 5, } + print('get_cinema_ver') + print(cinema_config) + print(db_config) try: db_conn = pymysql.Connect(**db_config) with db_conn.cursor(cursor=DictCursor) as db_cursor: