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

3
.gitignore vendored

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

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