Initial commit: Daily News App
企業內部新聞彙整與分析系統 - 自動新聞抓取 (Digitimes, 經濟日報, 工商時報) - AI 智慧摘要 (OpenAI/Claude/Ollama) - 群組管理與訂閱通知 - 已清理 Python 快取檔案 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
98
run.py
Normal file
98
run.py
Normal file
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
每日報導 APP - 啟動腳本
|
||||
執行此檔案即可啟動應用程式
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
# 設定 Windows 命令提示字元的編碼
|
||||
if sys.platform == 'win32':
|
||||
try:
|
||||
# 嘗試設定為 UTF-8
|
||||
os.system('chcp 65001 > nul')
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
sys.stderr.reconfigure(encoding='utf-8')
|
||||
except:
|
||||
pass
|
||||
|
||||
# 確保能找到 app 模組
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
|
||||
def safe_print(text):
|
||||
"""安全的列印函數,避免編碼錯誤"""
|
||||
try:
|
||||
print(text)
|
||||
except UnicodeEncodeError:
|
||||
# 如果無法顯示,移除特殊字元
|
||||
print(text.encode('ascii', 'ignore').decode('ascii'))
|
||||
|
||||
def main():
|
||||
"""主程式進入點"""
|
||||
safe_print("=" * 60)
|
||||
safe_print("[啟動] 每日報導 APP 啟動中...")
|
||||
safe_print("=" * 60)
|
||||
|
||||
# 檢查環境變數檔案
|
||||
env_file = Path(__file__).parent / ".env"
|
||||
if not env_file.exists():
|
||||
safe_print("[警告] .env 檔案不存在")
|
||||
safe_print("[提示] 請複製 .env.example 為 .env 並設定相關參數")
|
||||
safe_print(" 指令: copy .env.example .env")
|
||||
safe_print("=" * 60)
|
||||
response = input("是否繼續啟動? (y/N): ")
|
||||
if response.lower() != 'y':
|
||||
safe_print("[取消] 啟動已取消")
|
||||
return
|
||||
|
||||
# 檢查必要套件
|
||||
try:
|
||||
import fastapi
|
||||
import uvicorn
|
||||
import sqlalchemy
|
||||
except ImportError as e:
|
||||
safe_print(f"[錯誤] 缺少必要套件: {e}")
|
||||
safe_print("[提示] 請先安裝相依套件:")
|
||||
safe_print(" 指令: pip install -r requirements.txt")
|
||||
safe_print("=" * 60)
|
||||
return
|
||||
|
||||
# 啟動 FastAPI 應用程式
|
||||
try:
|
||||
import uvicorn
|
||||
from app.main import app
|
||||
|
||||
safe_print("[成功] 應用程式已準備就緒")
|
||||
safe_print("[網址] 伺服器位址: http://127.0.0.1:8000")
|
||||
safe_print("[文件] API 文件: http://127.0.0.1:8000/docs")
|
||||
safe_print("[健康] 健康檢查: http://127.0.0.1:8000/health")
|
||||
safe_print("=" * 60)
|
||||
safe_print("[提示] 按 Ctrl+C 停止伺服器")
|
||||
safe_print("=" * 60)
|
||||
|
||||
# 讀取環境變數判斷是否為 debug 模式
|
||||
from app.core.config import settings
|
||||
|
||||
uvicorn.run(
|
||||
"app.main:app",
|
||||
host="127.0.0.1",
|
||||
port=8000,
|
||||
reload=settings.debug,
|
||||
log_level="info"
|
||||
)
|
||||
except Exception as e:
|
||||
safe_print(f"[錯誤] 啟動失敗: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
safe_print("=" * 60)
|
||||
safe_print("[提示] 請檢查:")
|
||||
safe_print(" 1. .env 檔案是否正確設定")
|
||||
safe_print(" 2. 資料庫連線是否正常")
|
||||
safe_print(" 3. 相依套件是否完整安裝")
|
||||
safe_print("=" * 60)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user