-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_daily_quote.bat
78 lines (63 loc) · 2.35 KB
/
run_daily_quote.bat
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
@echo off
setlocal enabledelayedexpansion
:: Get the directory where the script is located
set "SCRIPT_DIR=%~dp0"
set "SCRIPT_DIR=%SCRIPT_DIR:~0,-1%"
:: Path to the virtual environment in the local directory
set "VENV_PATH=%SCRIPT_DIR%\venv"
:: Try to find Python 3 in the system
where python >nul 2>&1
if %ERRORLEVEL% equ 0 (
for /f "tokens=*" %%i in ('python -c "import sys; print(sys.version_info[0])"') do set PYTHON_VERSION=%%i
if !PYTHON_VERSION! equ 3 (
set "PYTHON_PATH=python"
)
) else (
where python3 >nul 2>&1
if %ERRORLEVEL% equ 0 (
set "PYTHON_PATH=python3"
) else (
echo Error: Python 3 not found
exit /b 1
)
)
echo Using Python at: %PYTHON_PATH%
:: Navigate to the script directory
cd /d "%SCRIPT_DIR%"
:: Check if the virtual environment exists; if not, create it and install dependencies
if not exist "%VENV_PATH%" (
echo %date% %time% – Virtual environment not found. Creating one...
%PYTHON_PATH% -m venv "%VENV_PATH%"
:: Activate the virtual environment
if exist "%VENV_PATH%\Scripts\activate.bat" (
call "%VENV_PATH%\Scripts\activate.bat"
) else (
echo Error: Virtual environment activation script not found
exit /b 1
)
echo %date% %time% – Installing dependencies from requirements.txt...
pip install -r requirements.txt
) else (
:: Activate the virtual environment
call "%VENV_PATH%\Scripts\activate.bat"
)
:: Run the Python script
echo %date% %time% – Running the daily_quote.py script...
python daily_quote.py
:: Check for changes in quote files
git status --porcelain | findstr /i "quotes.*\.txt" >nul
if %ERRORLEVEL% equ 0 (
echo %date% %time% – Changes detected in quote files. Updating the repository...
:: Add all quote files to the staging area
git add quotes*.txt
:: Get current date and time for commit message
for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /value') do set datetime=%%I
set "COMMIT_MESSAGE=Daily quote update: !datetime:~0,4!-!datetime:~4,2!-!datetime:~6,2! !datetime:~8,2!:!datetime:~10,2!:!datetime:~12,2!"
:: Commit and push changes
git commit -m "!COMMIT_MESSAGE!"
git push origin main
echo %date% %time% – Repository updated successfully.
) else (
echo %date% %time% – No changes detected in quote files. No update needed.
)
endlocal