From 723eac90b16bf4a150c5bd77436993d4fa691523 Mon Sep 17 00:00:00 2001 From: hanyuqing <1106611654@qq.com> Date: Mon, 22 Dec 2025 13:45:48 +0800 Subject: [PATCH] all --- app.py | 12 ++++++++++++ config.py | 11 +++++++++++ controller/LoginController.py | 2 +- python/app.py | 12 ------------ python/config.py | 11 ----------- python/web_main.py | 15 --------------- util/mysql_utils.py | 2 +- web_main.py | 15 +++++++++++++++ 8 files changed, 40 insertions(+), 40 deletions(-) create mode 100644 app.py create mode 100644 config.py delete mode 100644 python/app.py delete mode 100644 python/config.py delete mode 100644 python/web_main.py create mode 100644 web_main.py diff --git a/app.py b/app.py new file mode 100644 index 0000000..a67e49f --- /dev/null +++ b/app.py @@ -0,0 +1,12 @@ +import os +import sys + +from robyn import Robyn + +# 自动将 web_server 目录加入 Python 路径 +web_server_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +if web_server_path not in sys.path: + sys.path.insert(0, web_server_path) + + +app = Robyn(__file__) \ No newline at end of file diff --git a/config.py b/config.py new file mode 100644 index 0000000..ac78c07 --- /dev/null +++ b/config.py @@ -0,0 +1,11 @@ +# MySQL数据库配置 +# 请根据您的实际MySQL配置修改以下参数 + +MYSQL_CONFIG = { + "host": "localhost", # MySQL主机地址 + "port": 3306, # MySQL端口 + "user": "root", # MySQL用户名 + "password": "123456", # MySQL密码 + "database": "kg", # 数据库名 + "charset": "utf8mb4" # 字符 +} \ No newline at end of file diff --git a/controller/LoginController.py b/controller/LoginController.py index 71b7178..b048e10 100644 --- a/controller/LoginController.py +++ b/controller/LoginController.py @@ -1,5 +1,5 @@ from robyn import jsonify, Response -from python.app import app +from app import app from datetime import datetime, timedelta import uuid import json diff --git a/python/app.py b/python/app.py deleted file mode 100644 index a67e49f..0000000 --- a/python/app.py +++ /dev/null @@ -1,12 +0,0 @@ -import os -import sys - -from robyn import Robyn - -# 自动将 web_server 目录加入 Python 路径 -web_server_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -if web_server_path not in sys.path: - sys.path.insert(0, web_server_path) - - -app = Robyn(__file__) \ No newline at end of file diff --git a/python/config.py b/python/config.py deleted file mode 100644 index ac78c07..0000000 --- a/python/config.py +++ /dev/null @@ -1,11 +0,0 @@ -# MySQL数据库配置 -# 请根据您的实际MySQL配置修改以下参数 - -MYSQL_CONFIG = { - "host": "localhost", # MySQL主机地址 - "port": 3306, # MySQL端口 - "user": "root", # MySQL用户名 - "password": "123456", # MySQL密码 - "database": "kg", # 数据库名 - "charset": "utf8mb4" # 字符 -} \ No newline at end of file diff --git a/python/web_main.py b/python/web_main.py deleted file mode 100644 index 455c2df..0000000 --- a/python/web_main.py +++ /dev/null @@ -1,15 +0,0 @@ -from app import app -import controller.LoginController -import test1 # 👈 关键:导入 test1,触发 @app.get("/getData") 执行 -from service.UserService import init_mysql_connection -import os - -# 添加静态文件服务 -current_dir = os.path.dirname(os.path.abspath(__file__)) -resource_dir = os.path.join(current_dir, "resource") -if os.path.exists(resource_dir): - app.serve_directory("/resource", resource_dir) - print(f"静态资源目录已配置: {resource_dir}") - -if __name__ == "__main__": - init_mysql_connection() and app.start(host="0.0.0.0", port=8088) \ No newline at end of file diff --git a/util/mysql_utils.py b/util/mysql_utils.py index e3a73a8..73856da 100644 --- a/util/mysql_utils.py +++ b/util/mysql_utils.py @@ -1,6 +1,6 @@ import pymysql from typing import List, Dict, Any -from python.config import MYSQL_CONFIG +from config import MYSQL_CONFIG class MySQLClient: """MySQL客户端类""" diff --git a/web_main.py b/web_main.py new file mode 100644 index 0000000..571dd73 --- /dev/null +++ b/web_main.py @@ -0,0 +1,15 @@ +from app import app +import controller.LoginController +import python.test1 # 👈 关键:导入 test1,触发 @app.get("/getData") 执行 +from service.UserService import init_mysql_connection +import os + +# 添加静态文件服务 +current_dir = os.path.dirname(os.path.abspath(__file__)) +resource_dir = os.path.join(current_dir, "resource") +if os.path.exists(resource_dir): + app.serve_directory("/resource", resource_dir) + print(f"静态资源目录已配置: {resource_dir}") + +if __name__ == "__main__": + init_mysql_connection() and app.start(host="0.0.0.0", port=8088) \ No newline at end of file