Horoscope/header.bat

62 lines
1.2 KiB
Batchfile
Raw Normal View History

2024-09-28 20:35:08 +02:00
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "tmpFile=%TEMP%\~horoscope.py"
:: Variables
SET "pipR=pip install Pillow"
SET "py=python.exe"
:: Check python installation
!py! --version >NUL
:: Clean potential error or python version
CLS
IF ERRORLEVEL 1 (
ECHO Installation of Python not found, installation...
:: Install Python 3.11 from MS Store
ECHO Y | winget install -he 9NRWMJP3717K
ECHO Download and installation of dependencies...
:: Location of Python
SET "py=%LOCALAPPDATA%\Microsoft\WindowsApps\!py!"
:: Update pip
!py! -m pip install --upgrade pip
:: Install dependencies
!py! -m !pipR!
) ELSE (
:: Check dependencies
!py! -m !pipR! >NUL
)
:: Download images under %TEMP%\images
REM TODO
:: Write the program
CALL :getLine "::python_beg" "::python_end" > "!tmpFile!"
:: Run the program
PowerShell -Command "Start-Process cmd -Argument '/c START /B python !tmpFile!' -WindowStyle hidden"
EXIT /B
:getLine <beg str> <end str>
SET "bBegEnd=0"
FOR /F "usebackq delims=" %%i IN ("%~f0") do (
IF !bBegEnd! EQU 1 (
IF "%%i" EQU "%~2" ( EXIT /B )
SETLOCAL DISABLEDELAYEDEXPANSION
ECHO %%i
ENDLOCAL
) ELSE (
IF "%%i" EQU "%~1" ( SET "bBegEnd=1" )
)
)
ENDLOCAL
EXIT /B