-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_job_apply_bot.cmd
More file actions
74 lines (66 loc) · 2.48 KB
/
Copy pathstart_job_apply_bot.cmd
File metadata and controls
74 lines (66 loc) · 2.48 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
@echo off
setlocal
set "APP_DIR=%~dp0"
set "SERVER=%APP_DIR%server.py"
set "APP_URL=http://127.0.0.1:8000"
if not exist "%SERVER%" (
echo Could not find server.py next to this launcher.
pause
exit /b 1
)
rem Reuse this project's existing process when it is already running.
powershell -NoProfile -ExecutionPolicy Bypass -Command "$target = [IO.Path]::GetFullPath($env:SERVER); $found = Get-CimInstance Win32_Process -ErrorAction SilentlyContinue | Where-Object { $_.CommandLine -and $_.CommandLine.IndexOf($target, [StringComparison]::OrdinalIgnoreCase) -ge 0 }; if ($found) { exit 0 } else { exit 1 }"
if not errorlevel 1 goto wait_for_server
rem Do not silently open an unrelated service that happens to use port 8000.
powershell -NoProfile -ExecutionPolicy Bypass -Command "if (Get-NetTCPConnection -LocalPort 8000 -State Listen -ErrorAction SilentlyContinue) { exit 0 } else { exit 1 }"
if not errorlevel 1 (
echo Port 8000 is already in use by another program.
echo Stop that program, then run this launcher again.
pause
exit /b 1
)
set "PYTHON_CMD="
set "PYTHON_ARGS="
where pyw.exe >nul 2>&1
if not errorlevel 1 (
set "PYTHON_CMD=pyw.exe"
set "PYTHON_ARGS=-3"
)
if not defined PYTHON_CMD (
where pythonw.exe >nul 2>&1
if not errorlevel 1 set "PYTHON_CMD=pythonw.exe"
)
if not defined PYTHON_CMD (
where py.exe >nul 2>&1
if not errorlevel 1 (
set "PYTHON_CMD=py.exe"
set "PYTHON_ARGS=-3"
)
)
if not defined PYTHON_CMD (
where python.exe >nul 2>&1
if not errorlevel 1 set "PYTHON_CMD=python.exe"
)
if not defined PYTHON_CMD (
echo Python 3 was not found.
echo Install Python from python.org, then run this launcher again.
pause
exit /b 1
)
pushd "%APP_DIR%"
if /I "%PYTHON_CMD%"=="pyw.exe" start "" pyw.exe -3 "%SERVER%"
if /I "%PYTHON_CMD%"=="pythonw.exe" start "" pythonw.exe "%SERVER%"
if /I "%PYTHON_CMD%"=="py.exe" start "Job Apply Assistant" /min py.exe -3 "%SERVER%"
if /I "%PYTHON_CMD%"=="python.exe" start "Job Apply Assistant" /min python.exe "%SERVER%"
popd
:wait_for_server
powershell -NoProfile -ExecutionPolicy Bypass -Command "$deadline = (Get-Date).AddSeconds(12); do { try { $response = Invoke-WebRequest -UseBasicParsing -Uri $env:APP_URL -TimeoutSec 1; if ($response.StatusCode -eq 200) { exit 0 } } catch {}; Start-Sleep -Milliseconds 250 } while ((Get-Date) -lt $deadline); exit 1"
if errorlevel 1 (
echo The Job Apply Assistant did not start successfully.
echo Run: python server.py
echo in this folder to view the detailed error.
pause
exit /b 1
)
start "" "%APP_URL%"
endlocal