-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommit-art-general.py
72 lines (58 loc) · 2.66 KB
/
commit-art-general.py
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
import os
from datetime import datetime, timedelta
import pytz
# Define the pattern (7 rows for days, add as many columns as there are weeks in the image)
heart_pattern = [
[0, 1, 1, 0, 1, 1, 0], # Sunday
[1, 1, 1, 1, 1, 1, 1], # Monday
[1, 1, 1, 1, 1, 1, 1], # Tuesday
[1, 1, 1, 1, 1, 1, 1], # Wednesday
[0, 1, 1, 1, 1, 1, 0], # Thursday
[0, 0, 1, 1, 1, 0, 0], # Friday
[0, 0, 0, 1, 0, 0, 0], # Saturday
]
# Set the timezone
timezone = pytz.timezone("America/New_York")
# Start date for the heart: September 1st (Sunday)
start_date = datetime(2024, 9, 1)
# Verify Git repository
if not os.path.exists(".git"):
print("Error: This directory is not a Git repository.")
exit(1)
# Loop through the period and create commits based on the pattern
for week in range(7):
for day in range(7):
try:
commit_date = start_date + timedelta(weeks=week, days=day)
# Ensure index is valid
if 0 <= day < len(heart_pattern) and 0 <= week < len(heart_pattern[day]):
# Number of commits for the day
commit_count = heart_pattern[day][week]
for commit_num in range(commit_count):
# Localize the datetime to the specified timezone
commit_time = commit_date + timedelta(
hours=commit_num
) # Spread commits over the day
commit_time = timezone.localize(commit_time)
# Git date format
formatted_date = commit_time.strftime("%a %b %d %H:%M:%S %Y %z")
# Create a dummy file and make a commit with backdated time
with open("pixel.txt", "w") as file:
file.write(
f"Commit on {commit_time.strftime('%Y-%m-%d %H:%M:%S')} (Commit {commit_num + 1})\n"
)
os.system("git add pixel.txt")
commit_cmd = (
f'GIT_COMMITTER_DATE="{formatted_date}" '
f'git commit --date="{formatted_date}" '
f'-m "Commit on {commit_time.strftime("%Y-%m-%d %H:%M:%S")}"'
)
if os.system(commit_cmd) != 0:
print(
f"Error committing on {commit_time.strftime('%Y-%m-%d %H:%M:%S')}"
)
except IndexError:
print(f"Skipping invalid index at week {week}, day {day}")
# Push the commits to GitHub once all are created
if os.system("git push origin main") != 0:
print("Error: Git push failed. Check authentication and branch name.")