-
Notifications
You must be signed in to change notification settings - Fork 0
/
isitmybirthdayyet.py
51 lines (46 loc) · 1.43 KB
/
isitmybirthdayyet.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
from datetime import date
import datetime
import requests
import config
print("Running isitmybirthdayyet.py v0.2.1")
def getDadJoke():
url = "https://dad-jokes.p.rapidapi.com/random/joke"
headers = {
"X-RapidAPI-Host": config.apiHost,
"X-RapidAPI-Key": config.apiKey
}
response = requests.request("GET", url, headers=headers)
data = response.json()
# print(data)
body = data["body"]
for item in body:
setup = item["setup"]
punchline = item["punchline"]
print(setup)
answer = input("Ready for the punchline?\n")
if "y" in answer:
print(punchline)
# Ask again
anotherOneAnswer = input("Do you want another dad joke?\n")
if "y" in anotherOneAnswer:
getDadJoke()
def calculateAge(birthDate):
today = date.today()
age = today.year - birthDate.year - ((today.month, today.day) < (birthDate.month, birthDate.day))
return age
today = date.today()
if today.month == 4 and today.day == 18:
hex = "4861707079204269727468646179204c617721"
message = bytes.fromhex(hex).decode("utf-8")
print(message)
else:
birthDate = date(1986, 4, 18)
age = calculateAge(birthDate)
print("Currently you are", age, "years old.")
# Compute days until the birth date
birthDateThisYear = date(today.year, 4, 18)
daysBeforeBirthday = birthDateThisYear - today
print("Not your birthday yet. But in", daysBeforeBirthday.days, "days it will be.")
answer = input("Wanna here a dad joke instead?\n")
if "y" in answer:
getDadJoke()