Abdullah-Basar commited on
Commit
b6d8da7
Β·
verified Β·
1 Parent(s): fc6b9c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -39
app.py CHANGED
@@ -1,50 +1,52 @@
1
  import streamlit as st
2
  from datetime import datetime, timedelta
 
3
 
4
  # App Title and Description
5
- st.title("πŸŽ‚ Age Calculator")
6
  st.write("""
7
- Calculate your age in years, minutes, and seconds!
8
  See your next 5 birthdays and get a detailed textual output in English.
9
  """)
10
 
11
- # Input: Date of Birth
12
- dob = st.date_input("Enter your Date of Birth (YYYY-MM-DD):")
13
-
14
- # Calculate Age
15
- if dob:
16
- today = datetime.now()
17
- dob_datetime = datetime.combine(dob, datetime.min.time())
18
-
19
- age_years = today.year - dob.year - ((today.month, today.day) < (dob.month, dob.day))
20
- age_days = (today - dob_datetime).days
21
- age_minutes = age_days * 24 * 60
22
- age_seconds = age_minutes * 60
23
-
24
- # Display Age
25
- st.subheader("πŸ•’ Your Age:")
26
- st.write(f"**Years:** {age_years}")
27
- st.write(f"**Minutes:** {age_minutes:,}")
28
- st.write(f"**Seconds:** {age_seconds:,}")
29
-
30
- # Next 5 Birthdays
31
- st.subheader("πŸŽ‰ Next 5 Birthdays:")
32
- next_birthdays = []
33
- next_birthday = datetime(today.year, dob.month, dob.day)
34
- if next_birthday < today:
35
- next_birthday = datetime(today.year + 1, dob.month, dob.day)
36
-
37
- for _ in range(5):
38
- next_birthdays.append(next_birthday.strftime("%A, %d %B %Y"))
39
- next_birthday += timedelta(days=365 + (1 if (next_birthday.year % 4 == 0 and (next_birthday.year % 100 != 0 or next_birthday.year % 400 == 0)) else 0))
40
-
41
- for idx, birthday in enumerate(next_birthdays, start=1):
42
- st.write(f"{idx}. {birthday}")
43
-
44
- # English Textual Output
45
- st.subheader("πŸ“œ Age in English:")
46
- st.write(f"You are **{age_years} years old**, which is approximately **{age_minutes:,} minutes** or **{age_seconds:,} seconds**.")
47
- st.write("Your next five birthdays will be on the dates listed above.")
 
48
 
49
  # Footer
50
  st.write("---")
 
1
  import streamlit as st
2
  from datetime import datetime, timedelta
3
+ from dateutil.relativedelta import relativedelta
4
 
5
  # App Title and Description
6
+ st.title("πŸŽ‚ Advanced Age Calculator")
7
  st.write("""
8
+ Calculate your age in years, months, and days!
9
  See your next 5 birthdays and get a detailed textual output in English.
10
  """)
11
 
12
+ # Input Section
13
+ if st.button("Click to Enter Your Date of Birth"):
14
+ dob = st.date_input("Select Your Date of Birth (YYYY-MM-DD):")
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:
28
+ next_birthday = datetime(today.year + 1, dob.month, dob.day)
29
+
30
+ for _ in range(5):
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("---")