mirror of
https://github.com/This-weiyuqing/mi-fitness-health.git
synced 2026-10-18 03:03:49 +08:00
chore: localize CLI output and comments to Chinese
This commit is contained in:
1 parent
636d2857c3
commit
ebc94b50e9
5 files changed
+70
-71
No files matched your search
+45
-45
@@ -26,104 +26,104 @@ async def _check_adapter_health(adapter) -> tuple[bool, list[str], str | None]:
|
||||
def cmd_setup(args):
|
||||
if args.mode == "mi_fitness_cloud" and args.user_id and args.pass_token:
|
||||
save_mi_fitness_token(args.user_id, args.pass_token)
|
||||
config = Config(mode="mi_fitness_cloud", region=args.region or "ru")
|
||||
config = Config(mode="mi_fitness_cloud", region=args.region or "cn")
|
||||
save_config(config)
|
||||
print("✅ Конфигурация сохранена (mi_fitness_cloud)")
|
||||
print("✅ 配置已保存(mi_fitness_cloud)")
|
||||
print(f" User ID: {args.user_id}")
|
||||
print(f" Region: {config.region}")
|
||||
return
|
||||
|
||||
print(f"{PROGRAM_NAME} - Setup Wizard")
|
||||
print(f"{PROGRAM_NAME} - 配置向导")
|
||||
print("=" * 50)
|
||||
print()
|
||||
user_id = input("Mi Fitness user_id: ").strip()
|
||||
pass_token = input("Mi Fitness passToken: ").strip()
|
||||
region = input("Region [ru]: ").strip() or "ru"
|
||||
user_id = input("Mi Fitness user_id: ").strip()
|
||||
pass_token = input("Mi Fitness passToken: ").strip()
|
||||
region = input("区域 [cn]: ").strip() or "cn"
|
||||
if not user_id or not pass_token:
|
||||
print("❌ Требуются user_id и passToken")
|
||||
print("❌ 必须提供 user_id 和 passToken")
|
||||
sys.exit(1)
|
||||
save_mi_fitness_token(user_id, pass_token)
|
||||
config = Config(mode="mi_fitness_cloud", region=region)
|
||||
save_config(config)
|
||||
print("✅ Mi Fitness конфигурация сохранена!")
|
||||
print("✅ Mi Fitness 配置已保存!")
|
||||
|
||||
|
||||
def cmd_doctor(args):
|
||||
print(f"{PROGRAM_NAME} - Doctor")
|
||||
print(f"{PROGRAM_NAME} - 诊断")
|
||||
print("=" * 50)
|
||||
print()
|
||||
config_path = get_config_path()
|
||||
print(f"Конфигурация: {config_path}")
|
||||
print(f"配置文件: {config_path}")
|
||||
|
||||
if not config_path.exists():
|
||||
print("❌ Конфигурация не найдена")
|
||||
print(f" Запустите: {PROGRAM_NAME} setup")
|
||||
print("❌ 未找到配置文件")
|
||||
print(f" 请运行: {PROGRAM_NAME} setup")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
config = load_config()
|
||||
print("✅ Конфигурация загружена")
|
||||
print(f" Режим: {config.mode}")
|
||||
print("✅ 配置已加载")
|
||||
print(f" 模式: {config.mode}")
|
||||
user_id, pass_token = load_mi_fitness_token()
|
||||
if user_id and pass_token:
|
||||
print("✅ Mi Fitness credentials найдены")
|
||||
print("✅ 已找到 Mi Fitness 凭据")
|
||||
print(f" User ID: {user_id}")
|
||||
print(f" Region: {config.region}")
|
||||
adapter = MiFitnessCloudAdapter(
|
||||
user_id=user_id, pass_token=pass_token, region=config.region
|
||||
)
|
||||
connected, data_types, region = asyncio.run(_check_adapter_health(adapter))
|
||||
print(f" Подключение: {'✅' if connected else '❌'}")
|
||||
print(f" 连接状态: {'✅' if connected else '❌'}")
|
||||
if connected:
|
||||
print(f" Определённый регион: {region}")
|
||||
print(f" Типы данных: {', '.join(data_types)}")
|
||||
print(f" 识别到的区域: {region}")
|
||||
print(f" 数据类型: {', '.join(data_types)}")
|
||||
else:
|
||||
print("❌ Mi Fitness credentials не найдены")
|
||||
print(f" Запустите: {PROGRAM_NAME} setup")
|
||||
print("❌ 未找到 Mi Fitness 凭据")
|
||||
print(f" 请运行: {PROGRAM_NAME} setup")
|
||||
|
||||
print()
|
||||
print(f"База данных: {config.database_path}")
|
||||
print(f"数据库: {config.database_path}")
|
||||
if config.database_path.exists():
|
||||
Database(config.database_path)
|
||||
print("✅ База данных доступна")
|
||||
print("✅ 数据库可用")
|
||||
else:
|
||||
print("ℹ️ База данных будет создана при первом запуске")
|
||||
print("ℹ️ 数据库将在首次运行时创建")
|
||||
except Exception as e:
|
||||
print(f"❌ Ошибка загрузки конфигурации: {e}")
|
||||
print(f"❌ 加载配置失败: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
async def cmd_sync_async(args):
|
||||
print(f"{PROGRAM_NAME} - Sync")
|
||||
print(f"{PROGRAM_NAME} - 同步")
|
||||
print("=" * 50)
|
||||
print()
|
||||
|
||||
try:
|
||||
config = load_config()
|
||||
except Exception as e:
|
||||
print(f"❌ Ошибка загрузки конфигурации: {e}")
|
||||
print(f"❌ 加载配置失败: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
if config.mode == "not_configured":
|
||||
print("❌ Сервер не настроен")
|
||||
print(f" Запустите: {PROGRAM_NAME} setup")
|
||||
print("❌ 服务尚未配置")
|
||||
print(f" 请运行: {PROGRAM_NAME} setup")
|
||||
sys.exit(1)
|
||||
|
||||
user_id, pass_token = load_mi_fitness_token()
|
||||
if not user_id or not pass_token:
|
||||
print("❌ Mi Fitness credentials не найдены")
|
||||
print(f" Запустите: {PROGRAM_NAME} setup")
|
||||
print("❌ 未找到 Mi Fitness 凭据")
|
||||
print(f" 请运行: {PROGRAM_NAME} setup")
|
||||
sys.exit(1)
|
||||
|
||||
db = Database(config.database_path)
|
||||
adapter = MiFitnessCloudAdapter(user_id=user_id, pass_token=pass_token, region=config.region)
|
||||
if not await adapter.connect():
|
||||
print("❌ Не удалось подключиться к Mi Fitness API")
|
||||
print("❌ 无法连接到 Mi Fitness API")
|
||||
sys.exit(1)
|
||||
|
||||
sync_service = SyncService(adapter, db)
|
||||
data_types = [args.type] if args.type else adapter.get_available_data_types()
|
||||
print(f"Синхронизация {len(data_types)} типов данных...")
|
||||
print(f"正在同步 {len(data_types)} 种数据类型...")
|
||||
print()
|
||||
for data_type in data_types:
|
||||
try:
|
||||
@@ -132,12 +132,12 @@ async def cmd_sync_async(args):
|
||||
start_date=args.start_date,
|
||||
end_date=args.end_date,
|
||||
)
|
||||
print(f"✅ {data_type}: {result['added']} добавлено, {result['updated']} обновлено")
|
||||
print(f"✅ {data_type}: 新增 {result['added']} 条,更新 {result['updated']} 条")
|
||||
except Exception as e:
|
||||
print(f"❌ {data_type}: {e}")
|
||||
|
||||
print()
|
||||
print("Синхронизация завершена!")
|
||||
print("同步完成!")
|
||||
|
||||
|
||||
def cmd_sync(args):
|
||||
@@ -146,20 +146,20 @@ def cmd_sync(args):
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
prog=PROGRAM_NAME, description="MCP server for Mi Fitness data"
|
||||
prog=PROGRAM_NAME, description="小米运动健康数据 MCP Server"
|
||||
)
|
||||
subparsers = parser.add_subparsers(dest="command", help="Available commands")
|
||||
subparsers.add_parser("serve", help="Run MCP server")
|
||||
subparsers = parser.add_subparsers(dest="command", help="可用命令")
|
||||
subparsers.add_parser("serve", help="运行 MCP Server")
|
||||
|
||||
setup_parser = subparsers.add_parser("setup", help="Configure the server")
|
||||
setup_parser.add_argument("--mode", choices=["mi_fitness_cloud"], help="Setup mode")
|
||||
setup_parser = subparsers.add_parser("setup", help="配置服务")
|
||||
setup_parser.add_argument("--mode", choices=["mi_fitness_cloud"], help="配置模式")
|
||||
setup_parser.add_argument("--user-id", help="Mi Fitness user ID")
|
||||
setup_parser.add_argument("--pass-token", help="Mi Fitness passToken")
|
||||
setup_parser.add_argument("--region", help="Cloud region")
|
||||
setup_parser.add_argument("--region", help="云端区域")
|
||||
|
||||
subparsers.add_parser("doctor", help="Check configuration and diagnose issues")
|
||||
subparsers.add_parser("doctor", help="检查配置并诊断问题")
|
||||
|
||||
sync_parser = subparsers.add_parser("sync", help="Sync data from source")
|
||||
sync_parser = subparsers.add_parser("sync", help="从数据源同步数据")
|
||||
sync_parser.add_argument(
|
||||
"--type",
|
||||
choices=[
|
||||
@@ -172,10 +172,10 @@ def main():
|
||||
"stress",
|
||||
"abnormal_heart_beat",
|
||||
],
|
||||
help="Type of data to sync",
|
||||
help="要同步的数据类型",
|
||||
)
|
||||
sync_parser.add_argument("--start-date", help="Start date (YYYY-MM-DD)")
|
||||
sync_parser.add_argument("--end-date", help="End date (YYYY-MM-DD)")
|
||||
sync_parser.add_argument("--start-date", help="开始日期(YYYY-MM-DD)")
|
||||
sync_parser.add_argument("--end-date", help="结束日期(YYYY-MM-DD)")
|
||||
|
||||
args = parser.parse_args()
|
||||
if args.command == "serve" or args.command is None:
|
||||
|
||||
Reference in new issue
Block a user