khalidative commited on
Commit
77a75b4
1 Parent(s): db64cde

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -33
app.py CHANGED
@@ -1,7 +1,9 @@
1
  import streamlit as st
2
- from datetime import date
 
3
  import math
4
  import re
 
5
 
6
  # Assuming PrayTimes class is defined here or imported from praytimes.py
7
 
@@ -360,43 +362,43 @@ class PrayTimes():
360
  a = a - mode * (math.floor(a / mode))
361
  return a + mode if a < 0 else a
362
 
363
- # Initialize the PrayTimes object
364
- PT = PrayTimes()
365
-
366
- import streamlit as st
367
- from datetime import date
368
-
369
- # Assuming PrayTimes class is defined here or imported
370
-
371
- # Initialize the PrayTimes object
372
- PT = PrayTimes()
373
-
374
- st.title('Muslim Daily Prayer Timings Calculator')
375
-
376
- # Input fields for latitude and longitude
 
 
377
  latitude = st.number_input('Enter your latitude:', format='%f')
378
  longitude = st.number_input('Enter your longitude:', format='%f')
379
-
380
- # Dropdown for calculation method selection
381
- calc_method = st.selectbox('Select Calculation Method:', options=list(PT.methods.keys()))
382
-
383
- # Assuming timezone offset and DST (Daylight Saving Time); you may want to let the user input these
384
  timezone = st.number_input('Enter your timezone offset from UTC (e.g., -5 for EST):', format='%f')
385
  dst = st.checkbox('Check if currently observing Daylight Saving Time')
386
 
387
- # Button to show prayer times
388
- if st.button('Show Prayer Times'):
389
- # Set the calculation method based on user selection
390
- PT.setMethod(calc_method)
391
 
392
- # Get today's date
393
- today = date.today()
 
 
394
 
395
- # Get prayer times using the provided latitude, longitude, timezone, and today's date
396
- times = PT.getTimes(today, (latitude, longitude), timezone, dst)
 
 
 
397
 
398
- # Displaying the prayer times
399
- st.subheader('Prayer Times:')
400
- for time_name in ['Fajr', 'Sunrise', 'Dhuhr', 'Asr', 'Maghrib', 'Isha', 'Midnight']:
401
- st.write(f"{time_name}: {times[time_name.lower()]}")
402
-
 
1
  import streamlit as st
2
+ from datetime import date, timedelta
3
+ import calendar
4
  import math
5
  import re
6
+ import pandas as pd
7
 
8
  # Assuming PrayTimes class is defined here or imported from praytimes.py
9
 
 
362
  a = a - mode * (math.floor(a / mode))
363
  return a + mode if a < 0 else a
364
 
365
+ # Function to calculate prayer times for all days of a given month and year
366
+ def calculate_monthly_prayer_times(year, month, latitude, longitude, timezone, dst, method):
367
+ PT = PrayTimes(method)
368
+ num_days = calendar.monthrange(year, month)[1]
369
+ prayer_times = []
370
+ for day in range(1, num_days + 1):
371
+ times = PT.getTimes((year, month, day), (latitude, longitude), timezone, dst)
372
+ # Formatting for display
373
+ formatted_times = {prayer: times[prayer] for prayer in ['fajr', 'sunrise', 'dhuhr', 'asr', 'maghrib', 'isha']}
374
+ prayer_times.append(formatted_times)
375
+ return prayer_times
376
+
377
+ # Streamlit UI
378
+ st.title('Yearly Muslim Prayer Times Calendar')
379
+
380
+ # User input for location, calculation method, timezone, and DST
381
  latitude = st.number_input('Enter your latitude:', format='%f')
382
  longitude = st.number_input('Enter your longitude:', format='%f')
383
+ calc_method = st.selectbox('Select Calculation Method:', options=['MWL', 'ISNA', 'Egypt', 'Makkah', 'Karachi', 'Tehran', 'Jafari'])
 
 
 
 
384
  timezone = st.number_input('Enter your timezone offset from UTC (e.g., -5 for EST):', format='%f')
385
  dst = st.checkbox('Check if currently observing Daylight Saving Time')
386
 
387
+ # Generate prayer times for the current year
388
+ current_year = date.today().year
389
+ months = list(calendar.month_name)[1:] # Getting month names
390
+ selected_month = st.selectbox('Select Month:', options=months, index=date.today().month - 1)
391
 
392
+ # Display prayer times for the selected month
393
+ if st.button('Show Prayer Times for Month'):
394
+ month_index = months.index(selected_month) + 1
395
+ prayer_times = calculate_monthly_prayer_times(current_year, month_index, latitude, longitude, timezone, dst, calc_method)
396
 
397
+ # Creating the dataframe for display
398
+ df_prayer_times = pd.DataFrame(prayer_times)
399
+ df_prayer_times.index += 1 # Adjusting index to start from 1 to represent days of the month
400
+ df_prayer_times.index.name = 'Day'
401
+ df_prayer_times.columns = [col.capitalize() for col in df_prayer_times.columns] # Capitalize column names
402
 
403
+ st.write(f"Prayer Times for {selected_month} {current_year}")
404
+ st.dataframe(df_prayer_times)