Skip to content

Commit fc0529d

Browse files
authored
les gooooooo
1 parent 48b5017 commit fc0529d

1 file changed

Lines changed: 196 additions & 0 deletions

File tree

β€Žbirthday/birthday.pyβ€Ž

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
import os
2+
import re
3+
import random
4+
import urllib.request
5+
import urllib.error
6+
from datetime import date
7+
8+
OWNER = "TheM1ddleM1n"
9+
OWNER_NORMALISED = OWNER.lower()
10+
OWNER_BIRTHDAY = (6, 5)
11+
12+
GITHUB_USERNAME_RE = re.compile(r'^[a-zA-Z0-9][a-zA-Z0-9\-]{0,37}[a-zA-Z0-9]$|^[a-zA-Z0-9]$')
13+
14+
BIRTHDAY_MESSAGES = [
15+
"Hope your day is as amazing as your code!",
16+
"Wishing you a bug-free birthday and smooth deployments!",
17+
"May your birthday be full of joy, cake, and zero stack traces!",
18+
"Another year wiser, another year of awesome Python programs!",
19+
"Here's to you β€” keep building great things!",
20+
"May your commits always be clean and your birthdays always sweet!",
21+
"Wishing you infinite loops of happiness today!",
22+
"You're not getting older, your version number is just incrementing!",
23+
]
24+
25+
OWNER_BIRTHDAY_MESSAGES = [
26+
"The creator himself! PythonProgramsV3 wouldn't exist without you β€” happy birthday, TheM1ddleM1n!",
27+
"The mastermind behind it all turns another year older! Hope it's an epic one, TheM1ddleM1n!",
28+
"Happy birthday to the one who started it all! PythonProgramsV3 salutes you, TheM1ddleM1n!",
29+
"The legend himself! Wishing you the best birthday yet β€” you've earned it, TheM1ddleM1n!",
30+
"From every script, every commit, every contributor β€” happy birthday, TheM1ddleM1n!",
31+
]
32+
33+
IMPERSONATOR_MESSAGES = [
34+
"That username belongs to the creator of PythonProgramsV3. Nice try!",
35+
"You're not fooling anyone β€” that's TheM1ddleM1n's username!",
36+
"Impersonating the creator? Bold move. Blocked.",
37+
]
38+
39+
COUNTDOWN_MESSAGES = [
40+
"Keep coding until the big day arrives!",
41+
"Your birthday is loading... please wait!",
42+
"Almost there β€” stay bug-free until then!",
43+
"The countdown is on. Keep shipping great code!",
44+
"Not long now β€” save some cake for the rest of us!",
45+
]
46+
47+
OWNER_COUNTDOWN_MESSAGES = [
48+
"The creator's birthday is coming β€” PythonProgramsV3 is getting ready to celebrate!",
49+
"Counting down to the day the legend was born!",
50+
"The mastermind's birthday approaches. This repo can't wait!",
51+
]
52+
53+
54+
def validate_github_username(username):
55+
return bool(GITHUB_USERNAME_RE.match(username))
56+
57+
58+
def github_user_exists(username):
59+
url = f"https://api.github.com/users/{username}"
60+
req = urllib.request.Request(
61+
url,
62+
headers={"User-Agent": "PythonProgramsV3-BirthdayChecker"}
63+
)
64+
try:
65+
with urllib.request.urlopen(req, timeout=10) as response:
66+
return response.status == 200
67+
except urllib.error.HTTPError as e:
68+
if e.code == 404:
69+
return False
70+
print(f"GitHub API error: {e.code}")
71+
return False
72+
except urllib.error.URLError as e:
73+
print(f"Network error reaching GitHub API: {e.reason}")
74+
return False
75+
76+
77+
def days_until_birthday(birth_month, birth_day):
78+
today = date.today()
79+
next_bday = date(today.year, birth_month, birth_day)
80+
if next_bday < today:
81+
next_bday = date(today.year + 1, birth_month, birth_day)
82+
return (next_bday - today).days
83+
84+
85+
def verify_owner_token():
86+
token_input = os.environ.get("OWNER_TOKEN_INPUT", "").strip()
87+
token_secret = os.environ.get("OWNER_TOKEN_SECRET", "").strip()
88+
if not token_secret:
89+
return False
90+
return token_input == token_secret
91+
92+
93+
def main():
94+
username = os.environ.get("BIRTHDAY_USERNAME", "").strip()
95+
birthday_str = os.environ.get("BIRTHDAY_DATE", "").strip()
96+
97+
print("=" * 50)
98+
99+
if not username:
100+
print("No username provided. Exiting.")
101+
print("=" * 50)
102+
return
103+
104+
if not validate_github_username(username):
105+
print(f"'{username}' is not a valid GitHub username format.")
106+
print("Only letters, numbers, and hyphens are allowed (max 39 chars).")
107+
print("=" * 50)
108+
return
109+
110+
is_owner_username = username.lower() == OWNER_NORMALISED
111+
112+
if is_owner_username and not verify_owner_token():
113+
print(f"Username '{username}' requires the owner token to unlock creator mode.")
114+
print("Running as a standard user instead.")
115+
print("=" * 50)
116+
is_owner_username = False
117+
118+
print(f"Checking GitHub for user '{username}'...")
119+
120+
if not github_user_exists(username):
121+
print(f"No GitHub account found for '{username}'. Exiting.")
122+
print("=" * 50)
123+
return
124+
125+
print(f"GitHub user '{username}' verified.")
126+
print("=" * 50)
127+
128+
if not birthday_str:
129+
print("No birthday provided. Exiting.")
130+
print("=" * 50)
131+
return
132+
133+
try:
134+
parts = birthday_str.split("-")
135+
if len(parts) != 2:
136+
raise ValueError
137+
birth_month = int(parts[0])
138+
birth_day = int(parts[1])
139+
if not (1 <= birth_month <= 12 and 1 <= birth_day <= 31):
140+
raise ValueError
141+
except ValueError:
142+
print("Invalid birthday format. Please use MM-DD (e.g. 06-05).")
143+
print("=" * 50)
144+
return
145+
146+
is_owner_date_claim = (birth_month, birth_day) == OWNER_BIRTHDAY and not is_owner_username
147+
148+
if is_owner_date_claim:
149+
print(random.choice(IMPERSONATOR_MESSAGES))
150+
print("=" * 50)
151+
return
152+
153+
today = date.today()
154+
is_birthday = today.month == birth_month and today.day == birth_day
155+
156+
print(f"Hello, {username}!")
157+
print("=" * 50)
158+
159+
if is_birthday:
160+
if is_owner_username:
161+
message = random.choice(OWNER_BIRTHDAY_MESSAGES)
162+
print()
163+
print(" πŸ‘‘πŸŽ‚πŸŽ‰ HAPPY BIRTHDAY, CREATOR! πŸŽ‰πŸŽ‚πŸ‘‘")
164+
print()
165+
print(f" Happy Birthday from PythonProgramsV3, {username}!")
166+
print()
167+
print(f" {message}")
168+
print()
169+
else:
170+
message = random.choice(BIRTHDAY_MESSAGES)
171+
print()
172+
print(" πŸŽ‚πŸŽ‰πŸŽˆ HAPPY BIRTHDAY! πŸŽˆπŸŽ‰πŸŽ‚")
173+
print()
174+
print(f" Happy Birthday from PythonProgramsV3, {username}!")
175+
print()
176+
print(f" {message}")
177+
print()
178+
else:
179+
days = days_until_birthday(birth_month, birth_day)
180+
message = random.choice(
181+
OWNER_COUNTDOWN_MESSAGES if is_owner_username else COUNTDOWN_MESSAGES
182+
)
183+
print()
184+
if days == 1:
185+
print(f" πŸŽ‚ Your birthday is TOMORROW, {username}!")
186+
else:
187+
print(f" πŸ“… You have {days} days until your birthday, {username}!")
188+
print()
189+
print(f" {message}")
190+
print()
191+
192+
print("=" * 50)
193+
194+
195+
if __name__ == "__main__":
196+
main()

0 commit comments

Comments
Β (0)