# -*- coding: utf-8 -*-
"""
导出网站URL列表
"""
from app import create_app
from models import Site

def export_urls():
    """导出所有网站URL"""
    app = create_app('development')

    with app.app_context():
        sites = Site.query.order_by(Site.sort_order.desc()).all()

        if not sites:
            print("没有找到任何网站数据")
            return

        # 导出到文件
        filename = 'urls.txt'
        with open(filename, 'w', encoding='utf-8') as f:
            for site in sites:
                f.write(site.url + '\n')

        print(f"✓ 成功导出 {len(sites)} 个URL")
        print(f"  文件: {filename}")
        print("\nURL列表：")
        print("-" * 80)
        for url in [site.url for site in sites]:
            print(url)

if __name__ == '__main__':
    export_urls()
