Abdullah-Basar commited on
Commit
39dce55
Β·
verified Β·
1 Parent(s): c5b0f62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -25
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import streamlit as st
2
- from datetime import datetime, timedelta
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
- if st.button("Click to Enter Your Date of Birth"):
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
- # Next 5 Birthdays
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
- if st.button("Calculate Age and Next Birthdays"):
35
- # Display Age
36
- st.subheader("πŸ•’ Your Age:")
37
- st.write(f"**Years:** {age_years}")
38
- st.write(f"**Months:** {age_months}")
39
- st.write(f"**Days:** {age_days}")
40
-
41
- # Display Next 5 Birthdays
42
- st.subheader("πŸŽ‰ Next 5 Birthdays:")
43
- for idx, birthday in enumerate(next_birthdays, start=1):
44
- st.write(f"{idx}. {birthday}")
45
-
46
- # English Textual Output
47
- st.subheader("πŸ“œ Age in English:")
48
- st.write(f"You are **{age_years} years, {age_months} months, and {age_days} days old**.")
49
- st.write("Your next five birthdays will be on the dates listed above.")
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.")