This Python script automates the process of making daily commits to a Git repository. It appends the current date to a README.md
file, creates a commit with a randomly generated message, and pushes the changes to a remote repository. 🚀
Before running the script, ensure you have the following installed:
- Python 3.x 🐍: The script requires Python 3.
- GitPython 📦: A Python library used to interact with Git repositories.
You can install GitPython using pip:
pip install gitpython
-
Create a Configuration File 📝
Copy the provided
config.template.json
file toconfig.json
:cp config.template.json config.json
-
Edit the Configuration File ✏️
Open
config.json
in a text editor and modify the fields as needed:{ "repo_path": "/path/to/your/repository", "readme_path": "README.md", "commit_prefix": "Daily update 🌟:" }
repo_path
: The path to your Git repository on your local machine.readme_path
: The path to theREADME.md
file within your repository.commit_prefix
: A prefix for your commit message.
The script performs the following actions:
- Load Configuration 📂: Reads the
config.json
file to get repository details. - Generate Commit Message 🎨: Chooses a random animal and gemstone to include in the commit message.
- Append to README.md 📄: Adds the current date and time to the
README.md
file. - Create Commit 🗃️: Stages the changes and creates a commit with a message.
- Push Changes ⬆️: Pushes the commit to the remote repository.
-
Clone the Repository (if you haven’t already) 📥:
git clone https://github.com/Warckoooooo/daily-commit-python.git
-
Navigate to the Script Directory 🌍:
cd daily-commit-python
-
Run the Script
▶️ :python3 main.py
The script will automatically make a commit and push it to the remote repository based on the configuration provided.
To automate the execution of the script daily on Windows, you can use Task Scheduler.
-
Open Task Scheduler 🔍
Search for "Task Scheduler" in the Start menu and open it.
-
Create a Basic Task 🛠️
- Click on "Create Basic Task" in the Actions pane.
- Provide a name and description for your task.
- Choose "Daily" for the trigger and set the desired time.
- Select "Start a program" and browse to the Python executable (
python.exe
), typically located atC:\PythonXX\python.exe
. - In the "Add arguments" field, enter the full path to your script, for example:
"C:\path\to\daily-commit-python\main.py"
. - Finish the setup and ensure the task is enabled.
-
Verify the Task ✅
Make sure the task is listed and enabled in Task Scheduler. You can run it manually to test if it works correctly.
To automate the execution of the script daily on Linux, you can set up a cron job.
-
Open the Crontab Configuration ✏️
Edit your crontab file using the following command:
crontab -e
-
Add a Cron Job Entry 🕒
Add the following line to schedule the script to run daily at a specific time (e.g., 2:00 AM):
0 2 * * * /usr/bin/python3 /path/to/daily-commit-python/main.py >> /path/to/daily-commit-python/cron.log 2>&1
- Replace
/path/to/daily-commit-python/main.py
with the full path to yourmain.py
script. - The
>> /path/to/daily-commit-python/cron.log 2>&1
part redirects the script’s output and errors to a log file (cron.log
), which you can check for troubleshooting.
- Replace
-
Save and Exit 💾
Save the changes and exit the editor. The cron job is now scheduled to run daily at the specified time.
- Authentication Issues 🔑: Ensure you have set up the remote URL with the correct credentials or token. Refer to GitHub's documentation on Personal Access Tokens (PAT) for more details.
- File Paths 🗂️: Verify that the
repo_path
andreadme_path
inconfig.json
are correct and point to the appropriate locations. - Dependencies 📦: Make sure all required Python libraries are installed.
- Scheduled Task / Cron Job Issues 📜: Check the respective logs (
cron.log
for Linux, Task Scheduler history for Windows) for any errors or messages.
If you have suggestions or improvements for the script, feel free to submit a pull request or open an issue.