2026-01-08 13:53:19 +08:00
|
|
|
|
import os
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_base_path():
|
|
|
|
|
|
"""获取运行时路径 (兼容打包后的 exe 和开发环境)"""
|
|
|
|
|
|
if getattr(sys, 'frozen', False):
|
2026-02-06 10:08:49 +08:00
|
|
|
|
# 打包后:exe 所在目录
|
2026-01-08 13:53:19 +08:00
|
|
|
|
return os.path.dirname(sys.executable)
|
2026-02-06 10:08:49 +08:00
|
|
|
|
# 开发时:当前文件所在目录
|
2026-01-08 13:53:19 +08:00
|
|
|
|
return os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_static_path():
|
2026-02-03 17:15:42 +08:00
|
|
|
|
"""获取 web_dist 静态资源路径"""
|
2026-01-08 13:53:19 +08:00
|
|
|
|
if getattr(sys, 'frozen', False):
|
2026-02-03 17:15:42 +08:00
|
|
|
|
return os.path.join(sys._MEIPASS, 'web_dist')
|
|
|
|
|
|
return os.path.join(os.path.dirname(os.path.abspath(__file__)), 'web_dist')
|
2026-01-08 13:53:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
|
|
BASE_DIR = get_base_path()
|
|
|
|
|
|
|
2026-02-06 10:08:49 +08:00
|
|
|
|
# 规范化 instance 目录
|
2026-01-13 14:50:23 +08:00
|
|
|
|
INSTANCE_DIR = os.path.join(BASE_DIR, 'instance')
|
|
|
|
|
|
|
2026-02-06 10:08:49 +08:00
|
|
|
|
# 确保 instance 目录存在(防止第一次运行时报错)
|
|
|
|
|
|
if not os.path.exists(INSTANCE_DIR):
|
|
|
|
|
|
try:
|
|
|
|
|
|
os.makedirs(INSTANCE_DIR)
|
|
|
|
|
|
except Exception:
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
# [修改] 绝对路径拼接,并强制将 Windows 的 \ 转换为 /,避免 SQLite URI 报错
|
|
|
|
|
|
# 最终结果类似: sqlite:///D:/project/instance/monitor_data.db
|
|
|
|
|
|
_db_path = os.path.join(INSTANCE_DIR, "monitor_data.db").replace('\\', '/')
|
|
|
|
|
|
SQLALCHEMY_DATABASE_URI = f'sqlite:///{_db_path}'
|
|
|
|
|
|
|
2026-01-08 13:53:19 +08:00
|
|
|
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
|
|
|
|
|
|
|
|
|
|
|
# --- 定时任务配置 ---
|
|
|
|
|
|
SCHEDULER_API_ENABLED = True
|
2026-01-13 14:50:23 +08:00
|
|
|
|
SCHEDULER_TIMEZONE = "Asia/Shanghai"
|
2026-01-08 13:53:19 +08:00
|
|
|
|
|
2026-02-06 10:08:49 +08:00
|
|
|
|
# --- 爬虫配置 ---
|
2026-01-08 13:53:19 +08:00
|
|
|
|
CRAWLER_CONFIG = {
|
|
|
|
|
|
"106": {
|
|
|
|
|
|
"base_url": "http://106.75.72.40:7500/api/proxy/tcp",
|
|
|
|
|
|
"primary_auth": "Basic YWRtaW46bGljYWhr",
|
|
|
|
|
|
"login_payload": {"username": "admin", "password": "licahk", "recaptcha": ""}
|
|
|
|
|
|
},
|
|
|
|
|
|
"82": {
|
|
|
|
|
|
"base_url": "http://82.156.1.111/weather/php",
|
|
|
|
|
|
"login": {'username': 'renlixin', 'password': 'licahk', 'login': '123'}
|
|
|
|
|
|
}
|
2026-01-13 14:50:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-06 10:08:49 +08:00
|
|
|
|
# --- IoT 物联网卡接口配置 ---
|
2026-01-13 14:50:23 +08:00
|
|
|
|
IOT_BASE_URL = "https://iot.huskyiot.cn"
|
2026-02-06 10:08:49 +08:00
|
|
|
|
IOT_APP_ID = "44aQHTpx"
|
|
|
|
|
|
IOT_SECRET = "26833abf8786167a5cff5355cfc249981985124a"
|
|
|
|
|
|
IOT_USERNAME = "yrsy"
|
|
|
|
|
|
IOT_PASSWORD = "123456789"
|
2026-01-13 14:50:23 +08:00
|
|
|
|
IOT_URL_LOGIN = "/iot-api/system/auth/v1/get/token"
|
|
|
|
|
|
IOT_URL_PAGE = "/iot-api/platform/v1/card-info/query/page"
|
2026-02-06 10:08:49 +08:00
|
|
|
|
IOT_URL_DETAIL = "/iot-api/platform/v1/card-info/query/batch-card-detail"
|
|
|
|
|
|
|
|
|
|
|
|
# [Debug] 打印路径确认
|
|
|
|
|
|
print(f"配置文件已加载,数据库路径: {SQLALCHEMY_DATABASE_URI}")
|