Last active
December 17, 2023 14:25
-
-
Save AdityaMotale/6af394f490e320af43332ea6f5d3a859 to your computer and use it in GitHub Desktop.
A python script for generating random commits in a Git repository within a specified date range.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
⚠️ Warning: Git contributions do not necessarily reflect your talent or skill level. | |
The purpose of this script is educational, emphasizing the importance of meaningful contributions over quantity. | |
Script for generating random commits in a Git repository within a specified date range. | |
Usage: | |
1. Ensure you have Git installed on your system. | |
2. Make sure you have initiated the git repo. | |
3. Configure [Date] and [Time] variables according to your needs. | |
4. Run this script and sync the changes with GitHub. | |
👉 Note: This script uses subprocess to execute Git commands. Make sure to run it in a | |
directory where you have initialized a Git repository. | |
""" | |
from datetime import datetime, timedelta | |
import subprocess | |
import random | |
# Define base time range for commits | |
BASE_START_TIME = "14:00:00" | |
BASE_END_TIME = "22:00:00" | |
# Define time range for commit generation | |
START_DATE = "2023-02-01" | |
END_DATE = "2023-02-10" | |
def createActivity(start_date, end_date): | |
""" | |
Generate random commits within the specified date range. | |
:param start_date: Start date in the format "YYYY-MM-DD". | |
:param end_date: End date in the format "YYYY-MM-DD". | |
""" | |
# Convert start and end dates to datetime objects | |
start = datetime.strptime(start_date, "%Y-%m-%d") | |
end = datetime.strptime(end_date, "%Y-%m-%d") | |
# Calculate the number of days between start and end dates | |
delta = end - start | |
# Iterate over each day in the date range | |
for i in range(delta.days + 1): | |
# Calculate the current date in the iteration | |
current_date = start + timedelta(days=i) | |
# Generate a random number of commits for this date | |
num_commits = random.randint(1, 5) | |
# Iterate over the random number of commits for the current date | |
for _ in range(num_commits): | |
# Generate a random commit time within the base time range | |
random_hour = random.randint(14, 21) | |
random_minute = random.randint(0, 59) | |
random_second = random.randint(0, 59) | |
commit_time = f"{random_hour:02}:{random_minute:02}:{random_second:02}" | |
# Define the Git commit command with date and message | |
commands = [ | |
"git", | |
"commit", | |
"--allow-empty", | |
f"--date={current_date.strftime('%Y-%m-%d')} {commit_time}", | |
"-m", | |
f"Random commit {random.randint(1, 100)}", | |
] | |
# Execute the Git commit command using subprocess | |
process = subprocess.Popen( | |
commands, stdout=subprocess.PIPE, stderr=subprocess.PIPE | |
) | |
# Check for any errors during the execution | |
output, error = process.communicate() | |
# Print error or output information | |
if error: | |
print(f"Error: {error.decode()}") | |
else: | |
print(f"Output: {output.decode()}") | |
# Run the script | |
createActivity(START_DATE, END_DATE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment