forked from TRahulsingh/green-squares-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit.py
More file actions
144 lines (122 loc) Β· 4.34 KB
/
commit.py
File metadata and controls
144 lines (122 loc) Β· 4.34 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import os
import random
import datetime
import subprocess
import json
import pytz # Timezone support
# πΏ Expanded inspirational quotes
quotes = [
"Push yourself, because no one else is going to do it for you.",
"Success is the sum of small efforts, repeated.",
"Small steps every day.",
"One more brick in the wall of progress.",
"Consistency is more important than intensity.",
"Another line, another win!",
"Stay curious, keep learning.",
"Another commit to greatness.",
"Progress, not perfection.",
"Just showing up matters.",
"Every commit counts toward greatness.",
"Build something you're proud of.",
"Bit by bit, you create the masterpiece.",
"The habit of showing up wins the game.",
"Donβt break the streak β commit today!",
"From bugs to brilliance β keep coding!",
"Itβs not about perfection. Itβs about progress.",
"Youβre one step closer to your goal.",
"Keep calm and commit on.",
"Even a tiny push moves the needle."
]
# π Expanded commit messages
commit_messages = [
"π Boosting productivity with code magic!",
"π Painting the contribution graph today",
"π‘ A bright idea strikes again!",
"π§ Just thinking in Python",
"π₯ Staying consistent is key",
"π€ One more commit for the bot!",
"π Learning something new today",
"π Daily dose of code",
"π Keeping the graph alive",
"β¨ One step at a time",
"π― Another mark on the roadmap",
"β
Small win for the day",
"π¦ Packaging progress, one file at a time",
"π§ Tweaked, tuned, and tightened",
"π§ͺ Experimented with improvements",
"π Progress never looked better",
"π Thoughts turned into code",
"π οΈ Building habits, one commit at a time",
"π Slow and steady climb",
"π§ Another brick in the dev wall"
]
target_files = ["daily_log.txt", "progress.md", "inspiration.txt"]
# β° IST timezone & 12-hour format
# Time setup
ist = pytz.timezone('Asia/Kolkata')
now = datetime.datetime.now(ist)
weekday = now.weekday() # Monday = 0, Sunday = 6
date_key = now.strftime('%Y-%m-%d')
timestamp = now.strftime('%Y-%m-%d %I:%M:%S %p')
# Paths
counter_file = ".commit_tracker.json"
min_total = 3
max_total = 15
# Load or initialize tracking
if os.path.exists(counter_file):
with open(counter_file, "r") as f:
data = json.load(f)
else:
data = {}
# Track weekly commit days
def get_week_key(date):
return date.strftime("%Y-W%U") # Year-WeekNumber (Monday as first day)
week_key = get_week_key(now)
week_data = data.get("week_data", {})
week_commits = week_data.get(week_key, [])
# Choose 4 random days (only once per week)
if len(week_commits) == 0:
num_days = random.randint(3, 5) # Commit 3 to 5 days each week
week_commits = sorted(random.sample(range(7), num_days))
week_data[week_key] = week_commits
data["week_data"] = week_data
with open(counter_file, "w") as f:
json.dump(data, f)
# β Skip if today is not one of the selected commit days
if weekday not in week_commits:
print(f"π {now.strftime('%A')} not selected for this week. Skipping commits.")
exit()
# Daily count
done = data.get(date_key, 0)
remaining = max_total - done
if remaining <= 0:
print("β
Max commits reached for today.")
exit()
# Random number of commits
slot_commit = random.randint(1, 5)
slot_commit = min(slot_commit, remaining)
# Ensure min_total is met
if done + slot_commit < min_total and remaining <= 6:
slot_commit = min(min_total - done, remaining)
log_entries = []
# Do the commits
for _ in range(slot_commit):
quote = random.choice(quotes)
message = random.choice(commit_messages)
filename = random.choice(target_files)
with open(filename, "a") as f:
f.write(f"[{timestamp}] {quote}\n")
subprocess.run(["git", "add", filename])
subprocess.run(["git", "commit", "-m", message])
log_entries.append(f"[{timestamp}] - {message}")
# Update tracking
data[date_key] = done + slot_commit
data["week_data"] = week_data
with open(counter_file, "w") as f:
json.dump(data, f)
# Log
if slot_commit > 0:
with open("commit_log.txt", "a") as log:
log.write(f"[{timestamp}] +{slot_commit} commit(s)\n")
log.write("\n".join(log_entries) + "\n\n")
print(f"β
{slot_commit} commit(s) made at {timestamp}. Total today: {done + slot_commit}")