live-forum/server/crawler/build.spec
2026-03-24 11:27:37 +08:00

139 lines
3.5 KiB
Python

# -*- mode: python ; coding: utf-8 -*-
"""
PyInstaller 打包配置文件
用于打包字节直播数据采集工具
"""
import os
import sys
from pathlib import Path
# 获取 Playwright 浏览器路径
def get_playwright_browsers_path():
"""获取 Playwright 浏览器安装路径"""
import subprocess
result = subprocess.run(
[sys.executable, '-c', 'import playwright; print(playwright.__file__)'],
capture_output=True, text=True
)
playwright_path = Path(result.stdout.strip()).parent
# 常见的浏览器路径
possible_paths = [
Path.home() / '.cache' / 'ms-playwright', # Linux
Path(os.environ.get('LOCALAPPDATA', '')) / 'ms-playwright', # Windows
Path.home() / 'Library' / 'Caches' / 'ms-playwright', # macOS
]
for p in possible_paths:
if p.exists():
return str(p)
return None
# 项目路径
CRAWLER_DIR = Path(SPECPATH)
GUI_DIR = CRAWLER_DIR / 'gui'
COMMERCE_DIR = CRAWLER_DIR / 'commerce'
ENTERTAINMENT_DIR = CRAWLER_DIR / 'entertainment'
# Playwright 浏览器路径
playwright_browsers = get_playwright_browsers_path()
# 数据文件
datas = [
# 包含 commerce 模块
(str(COMMERCE_DIR / 'config'), 'commerce/config'),
(str(COMMERCE_DIR / 'core'), 'commerce/core'),
(str(COMMERCE_DIR / 'services'), 'commerce/services'),
(str(COMMERCE_DIR / 'utils'), 'commerce/utils'),
# 包含 entertainment 模块
(str(ENTERTAINMENT_DIR / 'config'), 'entertainment/config'),
(str(ENTERTAINMENT_DIR / 'core'), 'entertainment/core'),
(str(ENTERTAINMENT_DIR / 'services'), 'entertainment/services'),
(str(ENTERTAINMENT_DIR / 'utils'), 'entertainment/utils'),
]
# 如果找到 Playwright 浏览器,添加到数据文件
if playwright_browsers:
datas.append((playwright_browsers, 'ms-playwright'))
# 隐藏导入
hiddenimports = [
'customtkinter',
'PIL',
'PIL._tkinter_finder',
'playwright',
'playwright.sync_api',
'requests',
'pandas',
'sqlalchemy',
'apscheduler',
'dotenv',
'loguru',
'dateutil',
# 爬虫模块
'commerce',
'commerce.config',
'commerce.config.settings',
'commerce.core',
'commerce.core.browser_login',
'commerce.core.cookie_manager',
'commerce.core.api_client',
'commerce.services',
'commerce.services.crawler_service',
'commerce.services.daren_account_service',
'commerce.utils',
'commerce.utils.logger',
'entertainment',
'entertainment.config',
'entertainment.config.settings',
'entertainment.core',
'entertainment.core.browser_login',
'entertainment.core.cookie_manager',
'entertainment.core.api_client',
'entertainment.services',
'entertainment.services.crawler_service',
'entertainment.utils',
'entertainment.utils.logger',
]
a = Analysis(
[str(GUI_DIR / 'app.py')],
pathex=[str(CRAWLER_DIR)],
binaries=[],
datas=datas,
hiddenimports=hiddenimports,
hookspath=[],
hooksconfig={},
runtime_hooks=[str(CRAWLER_DIR / 'runtime_hook.py')],
excludes=[],
noarchive=False,
)
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='ByteDanceCrawler',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False, # 不显示控制台窗口
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon=None, # 可以添加图标路径
)