Added multi-python check, colors, and run menu

Added the ability to run the script with multiple versions of python installed and selected the proper version for the virtual environment. Added pretty colors. create a menu out of the run.bat that allows you to install the The prerequisites run the bot or open a command prompt within the installed environment.
pull/1816/head
theovit 2 years ago
parent b4d3b53069
commit fffe4ddd00

1
.gitignore vendored

@ -245,3 +245,4 @@ video_creation/data/envvars.txt
config.toml
*.exe
video_creation/data/videos.json

@ -3,32 +3,81 @@ setlocal enabledelayedexpansion
set VENV_DIR=.venv
set "requirements_file=requirements.txt"
:main
set "wrong_python=0"
cls
:: Check if Python version 3.10.x is installed and create/activate a virtual environment.
python --version 2>NUL | findstr /R "3.10" > NUL
if %errorlevel% NEQ 0 (
powershell write-host -fore Red It looks like python version 3.10.x isn't installed. Please refer to the documentation for help.
powershell write-host -fore Red https://reddit-video-maker-bot.netlify.app/docs/prerequisites
if exist "%VENV_DIR%" (
call:cecho red "Previous virtual environment detected. May cause issues if not deleted."
echo 
set /p "choice=Would you like to remove this virtual environment? [Y/N]:"
echo 
set "choice=!choice:~0,1!"
set "choice=!choice:~0,1!"
if /i "!choice!"=="Y" (
rmdir /s /q %VENV_DIR%
) else if /i "!choice!"=="N" (
call:cecho red "You have chosen not to remove the current virtual environment. Please note this may cause issues with the installation."
) else (
powershell write-host -fore Green Python 3.10 is installed and running.
call:cecho red "Invalid choice. Please enter Y or N."
goto :again
)
)
cls
python --version >nul 2>&1
if %errorlevel% EQU 0 (
:: Find the location of the Python executable
for /f %%i in ('where python') do (
set "python_path_check=%%i"
echo !python_path_check!
!python_path_check! --version 2>NUL | findstr /R "3.10" > NUL
if %errorlevel% EQU 0 (
echo python_path_check | findstr /R "Python310" > NUL
if %errorlevel% EQU 0 (
set "standalone=!python_path_check!"
)
echo python_path_check | findstr /R "WindowsApps" > NUL
if %errorlevel% EQU 0 (
set "WindowsApps=!python_path_check!"
)
) else (
set "wrong_python=1"
)
)
if NOT "!standalone!"=="" (
echo Using standalone Python
set "python_path=!standalone!"
goto python310
) else if NOT "!WindowsApps!"=="" (
echo Using WindowsStore Python
set "python_path=!WindowsApps!"
goto python310
)
if !wrong_python! EQU 1 (
goto wrong_python_display
)
) else (
goto wrong_python_display
)
:python310
call:cecho green "Python 3.10.x is installed and running."
:activate
if exist "%VENV_DIR%" (
echo Activating virtual environment...
call "%VENV_DIR%\Scripts\activate.bat"
) else (
echo Creating virtual environment...
python -m venv %VENV_DIR%
!python_path! -m venv %VENV_DIR%
goto activate
)
python.exe -m pip install --upgrade pip >NUL
:: Upgrading pip
python -m pip install --upgrade pip >NUL
if %errorlevel% equ 0 (
powershell write-host -fore Green Pip is up-to-date.
call:cecho green "Pip is up-to-date."
) else (
powershell write-host -fore Green Pip has been upgraded to the latest version.
call:cecho green "Pip has been upgraded to the latest version."
)
:: Check if requirements.txt exists
if not exist %requirements_file% (
powershell write-host -fore Red %requirements_file% does not exist.
call:cecho red "%requirements_file% does not exist."
exit /b 1
)
:: Loop through each line in requirements.txt and check if the package is installed
@ -36,40 +85,42 @@ if %errorlevel% NEQ 0 (
for /f "tokens=1 delims=~=" %%a in (%requirements_file%) do (
pip show %%a >nul 2>&1
if errorlevel 1 (
powershell write-host -fore Red %%a is not installed.
call:cecho red "%%a is not installed."
::echo %%a is not installed.
set "missing=1"
)
)
:: Check if any packages are missing
if defined missing (
powershell write-host -fore Yellow One or more required packages are missing.
call:cecho yellow "One or more required packages are missing."
:ask_for_choice
powershell write-host -fore Yellow Do you want to install them? [Y/N]:
set /p choice=
echo 
set /p "choice=Do you want to install them? [Y/N]:"
echo 
set "choice=!choice:~0,1!"
set "choice=!choice:~0,1!"
if /i "!choice!"=="Y" (
pip install -r "%requirements_file%"
if errorlevel 1 (
powershell write-host -fore Red Installation failed.
call:cecho red "Installation failed."
goto :ask_for_choice
) else (
powershell write-host -fore Green Installation successful.
call:cecho green "Installation successful."
)
) else if /i "!choice!"=="N" (
echo You chose not to install missing packages.
goto again
) else (
powershell write-host -fore Red Invalid choice. Please enter Y or N.
call:cecho red "Invalid choice. Please enter Y or N."
goto :ask_for_choice
)
) else (
powershell write-host -fore Green All required packages are installed.
call:cecho green "All required packages are installed."
)
:playwright_check
pip show playwright >nul 2>&1
if %errorlevel% equ 0 (
powershell write-host -fore Green Playwright is installed.
call:cecho green "Playwright is installed."
) else (
echo Installing Playwright...
python -m playwright install
@ -77,8 +128,9 @@ if %errorlevel% NEQ 0 (
goto playwright_check
)
:runbot?
powershell write-host -fore Yellow Would you like to run the bot now? [Y/N]:
set /p choice=
echo 
set /p "choice=Would you like to run the bot now? [Y/N]:"
echo 
set "choice=!choice:~0,1!"
set "choice=!choice:~0,1!"
if /i "!choice!"=="Y" (
@ -87,13 +139,13 @@ if %errorlevel% NEQ 0 (
) else if /i "!choice!"=="N" (
goto :again
) else (
powershell write-host -fore Red Invalid choice. Please enter Y or N.
call:cecho red "Invalid choice. Please enter Y or N."
goto :runbot?
)
)
:again
powershell write-host -fore Yellow Do you want to run the script again? [Y/N]:
set /p choice=
echo 
set /p "choice=Do you want to run the script again? [Y/N]:"
echo 
set "choice=!choice:~0,1!"
set "choice=!choice:~0,1!"
if /i "!choice!"=="Y" (
@ -101,10 +153,47 @@ if /i "!choice!"=="Y" (
) else if /i "!choice!"=="N" (
goto :exit
) else (
powershell write-host -fore Red Invalid choice. Please enter Y or N.
call:cecho red "Invalid choice. Please enter Y or N."
goto :again
)
endlocal
:exit
echo Press any key to exit ...
echo Press any key to Return to menu...
pause >nul
call run.bat
cmd /k
:wrong_python_display
call:cecho red "It looks like python version 3.10.x is not installed. Please refer to the documentation for help."
call:cecho red "https://reddit-video-maker-bot.netlify.app/docs/prerequisites"
call:cecho yellow "Control Click to install Python: https://apps.microsoft.com/store/detail/python-310/9PJPW5LDXLZ5"
goto again
EXIT /B %ERRORLEVEL%
:cecho
setlocal enabledelayedexpansion
set "color=%~1"
set "text=%~2"
if !color! == red (
set "colored_text=%text%"
)
if !color! == green (
set "colored_text=%text%"
)
if !color! == yellow (
set "colored_text=%text%"
)
if !color! == blue (
set "colored_text=%text%"
)
if !color! == magenta (
set "colored_text=%text%"
)
if !color! == cyan (
set "colored_text=%text%"
)
echo !colored_text!
endlocal
EXIT /B 0

@ -1,6 +1,38 @@
@echo off
set VENV_DIR=.venv
setlocal enabledelayedexpansion
:menu
cls
echo ######## MENU ########
echo 1. Install
echo 2. Run
echo 3. Open CMD (.vevn)
echo ######################
echo 
set /p "choice=Please make a selection :"
echo 
if /i "!choice!"=="1" (
call install.bat
) else if /i "!choice!"=="2" (
goto run
) else if /i "!choice!"=="3" (
if exist "%VENV_DIR%" (
cls
echo Activating virtual environment...
call "%VENV_DIR%\Scripts\activate.bat"
cmd /k
) else (
cls
call:cecho red "No virtual environment detected"
call:cecho red "Please select Install from the menu"
pause
goto menu
)
)else (
cls
goto menu
)
:run
if exist "%VENV_DIR%" (
echo Activating virtual environment...
call "%VENV_DIR%\Scripts\activate.bat"
@ -11,13 +43,13 @@ if exist "%VENV_DIR%" (
pause >nul
exit
)
) else (
setlocal enabledelayedexpansion
:again
powershell write-host -fore Yellow It does not look like the prerequisites for the bot had been installed.
powershell write-host -fore Yellow Would you like to do that now? [Y/N]:
set /p choice=
cls
call:cecho yellow "It does not look like the prerequisites for the bot had been installed."
echo 
set /p "choice=Would you like to do that now? [Y/N]:"
echo 
set "choice=!choice:~0,1!"
set "choice=!choice:~0,1!"
if /i "!choice!"=="Y" (
@ -26,8 +58,36 @@ if exist "%VENV_DIR%" (
exit
) else (
cls
powershell write-host -fore Red Invalid choice. Please enter Y or N.
call:cecho red "Invalid choice. Please enter Y or N."
goto :again
)
)
endlocal
EXIT /B %ERRORLEVEL%
:cecho
setlocal enabledelayedexpansion
set "color=%~1"
set "text=%~2"
if !color! == red (
set "colored_text=%text%"
)
if !color! == green (
set "colored_text=%text%"
)
if !color! == yellow (
set "colored_text=%text%"
)
if !color! == blue (
set "colored_text=%text%"
)
if !color! == magenta (
set "colored_text=%text%"
)
if !color! == cyan (
set "colored_text=%text%"
)
echo !colored_text!
endlocal
EXIT /B 0
Loading…
Cancel
Save