#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
初始化應用程式腳本
"""

import os
import sys
sys.path.append('.')

def init_application():
    """初始化應用程式"""
    try:
        print("Initializing application...")
        
        from app import create_app
        app = create_app('development')
        print("App created successfully")
        
        with app.app_context():
            from app import db
            print("Database tables created")
            
            # 檢查表格是否建立
            import pymysql
            connection = pymysql.connect(
                host='mysql.theaken.com',
                port=33306,
                user='A060',
                password='WLeSCi0yhtc7',
                database='db_A060',
                charset='utf8mb4'
            )
            cursor = connection.cursor()
            cursor.execute('SHOW TABLES LIKE "dt_%"')
            tables = cursor.fetchall()
            
            print("\nDocument Translator Tables:")
            for table in tables:
                print(f"- {table[0]}")
            
            connection.close()
        
        return True
        
    except Exception as e:
        print(f"Initialization failed: {e}")
        return False

if __name__ == '__main__':
    init_application()