Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import streamlit as st
|
2 |
-
from datetime import datetime
|
3 |
from dateutil.relativedelta import relativedelta
|
4 |
|
5 |
# App Title and Description
|
@@ -10,18 +10,20 @@ See your next 5 birthdays and get a detailed textual output in English.
|
|
10 |
""")
|
11 |
|
12 |
# Input Section with a minimum date of January 1, 1950
|
13 |
-
|
14 |
-
dob = st.date_input("Select Your Date of Birth (YYYY-MM-DD):", min_value=datetime(1950, 1, 1))
|
15 |
|
|
|
|
|
16 |
if dob:
|
17 |
-
# Calculate Age
|
18 |
today = datetime.now()
|
19 |
dob_datetime = datetime.combine(dob, datetime.min.time())
|
|
|
|
|
20 |
age_years = today.year - dob.year - ((today.month, today.day) < (dob.month, dob.day))
|
21 |
age_months = relativedelta(today, dob_datetime).months
|
22 |
age_days = (today - dob_datetime).days % 30 # Approximation for days in the current month
|
23 |
|
24 |
-
#
|
25 |
next_birthdays = []
|
26 |
next_birthday = datetime(today.year, dob.month, dob.day)
|
27 |
if next_birthday < today:
|
@@ -31,23 +33,20 @@ if st.button("Click to Enter Your Date of Birth"):
|
|
31 |
next_birthdays.append(next_birthday.strftime("%A, %d %B %Y"))
|
32 |
next_birthday = next_birthday.replace(year=next_birthday.year + 1)
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
# Footer
|
52 |
-
st.write("---")
|
53 |
-
st.markdown("π‘ **Developed by Abdullah**")
|
|
|
1 |
import streamlit as st
|
2 |
+
from datetime import datetime
|
3 |
from dateutil.relativedelta import relativedelta
|
4 |
|
5 |
# App Title and Description
|
|
|
10 |
""")
|
11 |
|
12 |
# Input Section with a minimum date of January 1, 1950
|
13 |
+
dob = st.date_input("Select Your Date of Birth (YYYY-MM-DD):", min_value=datetime(1950, 1, 1))
|
|
|
14 |
|
15 |
+
# Button to trigger calculation
|
16 |
+
if st.button("Calculate Age and Next Birthdays"):
|
17 |
if dob:
|
|
|
18 |
today = datetime.now()
|
19 |
dob_datetime = datetime.combine(dob, datetime.min.time())
|
20 |
+
|
21 |
+
# Calculate age in years, months, and days
|
22 |
age_years = today.year - dob.year - ((today.month, today.day) < (dob.month, dob.day))
|
23 |
age_months = relativedelta(today, dob_datetime).months
|
24 |
age_days = (today - dob_datetime).days % 30 # Approximation for days in the current month
|
25 |
|
26 |
+
# Calculate next 5 birthdays
|
27 |
next_birthdays = []
|
28 |
next_birthday = datetime(today.year, dob.month, dob.day)
|
29 |
if next_birthday < today:
|
|
|
33 |
next_birthdays.append(next_birthday.strftime("%A, %d %B %Y"))
|
34 |
next_birthday = next_birthday.replace(year=next_birthday.year + 1)
|
35 |
|
36 |
+
# Display Age
|
37 |
+
st.subheader("π Your Age:")
|
38 |
+
st.write(f"**Years:** {age_years}")
|
39 |
+
st.write(f"**Months:** {age_months}")
|
40 |
+
st.write(f"**Days:** {age_days}")
|
41 |
+
|
42 |
+
# Display Next 5 Birthdays
|
43 |
+
st.subheader("π Next 5 Birthdays:")
|
44 |
+
for idx, birthday in enumerate(next_birthdays, start=1):
|
45 |
+
st.write(f"{idx}. {birthday}")
|
46 |
+
|
47 |
+
# English Textual Output
|
48 |
+
st.subheader("π Age in English:")
|
49 |
+
st.write(f"You are **{age_years} years, {age_months} months, and {age_days} days old**.")
|
50 |
+
st.write("Your next five birthdays will be on the dates listed above.")
|
51 |
+
else:
|
52 |
+
st.write("Please select a valid date of birth.")
|
|
|
|
|
|