Repository navigation
Expand file tree
/
Copy pathstart.bat
More file actions
217 lines (196 loc) · 6.23 KB
/
Copy pathstart.bat
File metadata and controls
217 lines (196 loc) · 6.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
@echo off
chcp 65001 > nul
:: 强制在持久cmd窗口中运行
if "%1"=="" (
cmd /k "%~f0" run
exit /b
)
title WeChat Article API Service
echo.
echo ========================================
echo WeChat Article API Service v1.0.0
echo FastAPI Edition - One-Click Startup
echo ========================================
echo.
:: Configuration variables
set PROJECT_NAME=wechat-article-api
set SERVICE_PORT=5000
set PYTHON_VERSION=3.8
set VENV_NAME=venv
:: Step 1: Check Python environment
echo [94m[1/6] Checking Python environment...[0m
python --version >nul 2>&1
if errorlevel 1 (
echo [91mX Python is not installed or not in PATH[0m
echo Please install Python %PYTHON_VERSION%+ and add to PATH
echo Download from: https://www.python.org/downloads/
pause
exit /b 1
)
for /f "tokens=2" %%i in ('python --version') do set INSTALLED_PYTHON=%%i
echo [92m+ Python version: %INSTALLED_PYTHON%[0m
:: Check pip
pip --version >nul 2>&1
if errorlevel 1 (
echo [91mX pip is not installed[0m
echo Please install pip
pause
exit /b 1
)
echo [92m+ pip is installed[0m
:: Step 2: Create virtual environment
echo.
echo [94m[2/6] Creating Python virtual environment...[0m
if exist "%VENV_NAME%" (
echo [93m! Virtual environment already exists, skipping creation[0m
) else (
python -m venv %VENV_NAME%
if errorlevel 1 (
echo [91mX Virtual environment creation failed[0m
pause
exit /b 1
)
echo [92m+ Virtual environment created successfully[0m
)
:: Activate virtual environment
call %VENV_NAME%\Scripts\activate.bat
if errorlevel 1 (
echo [91mX Virtual environment activation failed[0m
pause
exit /b 1
)
echo [92m+ Virtual environment activated[0m
:: Step 3: Install dependencies
echo.
echo [94m[3/6] Installing Python dependencies...[0m
if exist "requirements.txt" (
pip install -r requirements.txt
if errorlevel 1 (
echo [91mX Dependencies installation failed[0m
pause
exit /b 1
)
echo [92m+ Dependencies installed successfully[0m
) else (
echo [93m! requirements.txt not found, installing core dependencies manually[0m
pip install fastapi uvicorn httpx python-dotenv
if errorlevel 1 (
echo [91mX Core dependencies installation failed[0m
pause
exit /b 1
)
echo [92m+ Core dependencies installed successfully[0m
)
:: Step 4: Check .env configuration
echo.
echo [94m[4/6] Checking configuration file...[0m
if not exist ".env" (
echo [93m! .env file not found, creating from template...[0m
if exist "env.example" (
copy env.example .env >nul
echo [92m+ .env file created from env.example[0m
) else (
echo [93m! env.example not found, creating basic .env file...[0m
(
echo # WeChat Article API Configuration
echo # Auto-generated by start.bat
echo.
echo # Authentication Info ^(Auto-filled after login^)
echo WECHAT_TOKEN=
echo WECHAT_COOKIE=
echo WECHAT_FAKEID=
echo WECHAT_NICKNAME=
echo WECHAT_EXPIRE_TIME=
echo.
echo # Service Configuration
echo PORT=5000
echo HOST=0.0.0.0
echo DEBUG=false
echo.
echo # Rate Limiting
echo RATE_LIMIT_GLOBAL=10
echo RATE_LIMIT_PER_IP=5
echo RATE_LIMIT_ARTICLE_INTERVAL=3
) > .env
echo [92m+ Basic .env file created[0m
)
echo.
echo [93m========================================[0m
echo [93m First-time Setup[0m
echo [93m========================================[0m
echo.
echo [92mNext Steps:[0m
echo 1. Service will start in a moment
echo 2. Visit: http://localhost:5000/login.html
echo 3. Scan QR code with WeChat
echo 4. Login credentials will be saved automatically
echo.
echo [93m========================================[0m
echo.
) else (
echo [92m+ .env configuration file found[0m
:: Check required configuration items
findstr /C:"WECHAT_TOKEN=" .env | findstr /V "WECHAT_TOKEN=$" | findstr /V "WECHAT_TOKEN= *$" >nul 2>nul
if errorlevel 1 (
echo [93m! WeChat credentials not configured yet[0m
echo [93m Please visit http://localhost:5000/login.html to login[0m
) else (
echo [92m+ WeChat login credentials configured[0m
)
)
echo.
:: Step 5: Detect system configuration
echo [94m[5/6] Detecting system configuration...[0m
:: Get CPU cores
for /f "tokens=2 delims==" %%a in ('wmic cpu get NumberOfLogicalProcessors /value ^| find "="') do set CPU_CORES=%%a
if not defined CPU_CORES set CPU_CORES=4
:: Get memory size (GB)
for /f "tokens=2 delims==" %%a in ('wmic computersystem get TotalPhysicalMemory /value ^| find "="') do set MEMORY_BYTES=%%a
if defined MEMORY_BYTES (
set /a MEMORY_GB=MEMORY_BYTES/1073741824
) else (
set MEMORY_GB=8
)
echo [92m+ System configuration:[0m
echo CPU cores: %CPU_CORES%
echo Memory: %MEMORY_GB%GB
echo.
:: Step 6: Start service
echo [94m[6/6] Starting FastAPI service...[0m
echo.
echo ========================================
echo [92mService Startup Information[0m
echo ========================================
echo.
echo [94mAccess URLs:[0m
echo - Admin Panel: http://localhost:%SERVICE_PORT%/admin.html
echo - Login Page: http://localhost:%SERVICE_PORT%/login.html
echo - API Docs: http://localhost:%SERVICE_PORT%/api/docs
echo - ReDoc: http://localhost:%SERVICE_PORT%/api/redoc
echo - Health: http://localhost:%SERVICE_PORT%/api/health
echo.
echo [94mCore Features:[0m
echo + Article Retrieval - POST /api/article
echo + Article List - GET /api/public/articles
echo + Article Search - GET /api/public/articles/search
echo + Account Search - GET /api/public/searchbiz
echo + Image Proxy - GET /api/image
echo + Auto Rate Limiting
echo + Webhook Notifications
echo.
echo [94mSystem Info:[0m
echo CPU: %CPU_CORES% cores
echo Memory: %MEMORY_GB%GB
echo.
echo ========================================
echo.
echo [93mFirst time? Please visit login page to scan QR code:[0m
echo =^> http://localhost:%SERVICE_PORT%/login.html
echo.
echo [93mTip: Press Ctrl+C to stop service[0m
echo.
:: Start service
python app.py
echo.
echo [92mService stopped[0m
pause