Skip to content

Commit 17f5e3d

Browse files
Add: prayer-summary for dynamic prayer times (#1013)
* Add: prayer-summary for dynamic prayer times * Rename prayer-summary.sh to prayer-summary.template.sh * Add template configuration, dependencies, and author metadata
1 parent bacd96a commit 17f5e3d

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#!/bin/bash
2+
3+
# How to use this script?
4+
# It's a template which needs further setup. Duplicate the file,
5+
# remove `.template.` from the filename and set your city and country below.
6+
# Optionally, adjust the calculation method to fit your location.
7+
#
8+
# API: https://aladhan.com/prayer-times-api
9+
10+
# Dependency: This script requires `jq` cli installed: https://stedolan.github.io/jq/
11+
# Install via homebrew: `brew install jq`
12+
13+
# Required parameters:
14+
# @raycast.schemaVersion 1
15+
# @raycast.title Prayer Summary
16+
# @raycast.mode inline
17+
# @raycast.refreshTime 2m
18+
19+
# Optional parameters:
20+
# @raycast.icon 🕌
21+
# @raycast.packageName Culture
22+
23+
# Documentation:
24+
# @raycast.description Get the current and next prayer times for a specific city and country.
25+
# @raycast.author Muneeb Ajaz
26+
# @raycast.authorURL https://github.com/mianmuneebajaz
27+
28+
29+
# Configuration
30+
31+
# Set your city and country below:
32+
# 1. Replace CITY with your city name (e.g., "London")
33+
# 2. Replace COUNTRY with your country name (e.g., "United Kingdom")
34+
CITY=""
35+
COUNTRY=""
36+
37+
# Calculation method (default: 3 for Muslim World League - MWL)
38+
# Common methods:
39+
# 1 - University of Islamic Sciences, Karachi
40+
# 2 - Islamic Society of North America (ISNA)
41+
# 3 - Muslim World League (MWL)
42+
# 4 - Umm Al-Qura University, Makkah
43+
# 5 - Egyptian General Authority of Survey
44+
# See https://aladhan.com/prayer-times-api for all methods
45+
METHOD="3"
46+
47+
48+
# Main program
49+
50+
if ! command -v jq &> /dev/null; then
51+
echo "jq is required (https://stedolan.github.io/jq/)"
52+
exit 1
53+
fi
54+
55+
if [ -z "$CITY" ] || [ -z "$COUNTRY" ]; then
56+
echo "City and Country are required"
57+
exit 1
58+
fi
59+
60+
DATA=$(curl -s -L "http://api.aladhan.com/v1/timingsByCity?city=${CITY}&country=${COUNTRY}&method=${METHOD}")
61+
62+
if [ -z "$DATA" ]; then
63+
echo "Unable to fetch prayer times"
64+
exit 1
65+
fi
66+
67+
get_time() {
68+
echo "$DATA" | jq -r ".data.timings.$1"
69+
}
70+
71+
FAJR=$(get_time "Fajr")
72+
DHUHR=$(get_time "Dhuhr")
73+
ASR=$(get_time "Asr")
74+
MAGHRIB=$(get_time "Maghrib")
75+
ISHA=$(get_time "Isha")
76+
77+
# Convert 24h to 12h format
78+
to_ampm() {
79+
date -j -f "%H:%M" "$1" "+%I:%M %p" 2>/dev/null
80+
}
81+
82+
PRAYER_NAMES=("Fajr" "Dhuhr" "Asr" "Maghrib" "Isha")
83+
PRAYER_TIMES=("$FAJR" "$DHUHR" "$ASR" "$MAGHRIB" "$ISHA")
84+
85+
epoch_today() {
86+
date -j -f "%Y-%m-%d %H:%M" "$(date +%Y-%m-%d) $1" "+%s"
87+
}
88+
89+
NOW=$(date +%s)
90+
91+
CURRENT="None (before Fajr)"
92+
NEXT=""
93+
NEXT_TIME=""
94+
NEXT_EPOCH=0
95+
LAST=""
96+
97+
for i in "${!PRAYER_NAMES[@]}"; do
98+
name="${PRAYER_NAMES[$i]}"
99+
time="${PRAYER_TIMES[$i]}"
100+
ep=$(epoch_today "$time")
101+
102+
if [ "$ep" -le "$NOW" ]; then
103+
LAST="$name"
104+
elif [ -z "$NEXT" ]; then
105+
NEXT="$name"
106+
NEXT_TIME="$time"
107+
NEXT_EPOCH="$ep"
108+
fi
109+
done
110+
111+
if [ -n "$LAST" ]; then
112+
CURRENT="$LAST"
113+
fi
114+
115+
# After Isha, next prayer is tomorrow's Fajr
116+
if [ -z "$NEXT" ]; then
117+
NEXT="Fajr (tomorrow)"
118+
NEXT_TIME="$FAJR"
119+
NEXT_EPOCH=$(($(epoch_today "$FAJR") + 86400))
120+
fi
121+
122+
DIFF=$((NEXT_EPOCH - NOW))
123+
H=$((DIFF / 3600))
124+
M=$(((DIFF % 3600) / 60))
125+
COUNTDOWN="${H}h ${M}m"
126+
127+
NEXT_AM=$(to_ampm "$NEXT_TIME")
128+
129+
echo "Current: $CURRENT | Next: $NEXT at $NEXT_AM in $COUNTDOWN"

0 commit comments

Comments
 (0)