From 6b303980c1f6f0d66611cf483b24b9d517f0ae02 Mon Sep 17 00:00:00 2001 From: Muneeb Date: Wed, 26 Nov 2025 17:43:28 +0500 Subject: [PATCH 1/3] Add: prayer-summary for dynamic prayer times --- commands/culture/prayer-summary.sh | 107 +++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 commands/culture/prayer-summary.sh diff --git a/commands/culture/prayer-summary.sh b/commands/culture/prayer-summary.sh new file mode 100644 index 000000000..8957bb654 --- /dev/null +++ b/commands/culture/prayer-summary.sh @@ -0,0 +1,107 @@ +#!/bin/bash + +# Required parameters: +# @raycast.schemaVersion 1 +# @raycast.title Prayer Summary +# @raycast.description Get the prayer times for the current day +# @raycast.mode inline +# @raycast.refreshTime 2m + +# Optional parameters: +# @raycast.icon 🕌 + +CITY="Lahore" +COUNTRY="Pakistan" +METHOD=13 + +DATA=$(curl -s -L "http://api.aladhan.com/v1/timingsByCity?city=$CITY&country=$COUNTRY&method=$METHOD") + +if [ -z "$DATA" ]; then + echo "⚠️ Error: Unable to fetch prayer times" + exit 0 +fi + +get_time() { + echo "$DATA" | jq -r ".data.timings.$1" +} + +FAJR=$(get_time Fajr) +DHUHR=$(get_time Dhuhr) +ASR=$(get_time Asr) +MAGHRIB=$(get_time Maghrib) +ISHA=$(get_time Isha) + +# Convert 24h → 12h format +to_ampm() { + date -j -f "%H:%M" "$1" "+%I:%M %p" 2>/dev/null +} + +FAJR_AM=$(to_ampm "$FAJR") +DHUHR_AM=$(to_ampm "$DHUHR") +ASR_AM=$(to_ampm "$ASR") +MAGHRIB_AM=$(to_ampm "$MAGHRIB") +ISHA_AM=$(to_ampm "$ISHA") + +PRAYER_NAMES=("Fajr" "Dhuhr" "Asr" "Maghrib" "Isha") +PRAYER_TIMES=("$FAJR" "$DHUHR" "$ASR" "$MAGHRIB" "$ISHA") + +epoch_today() { + date -j -f "%Y-%m-%d %H:%M" "$(date +%Y-%m-%d) $1" "+%s" +} + +NOW=$(date +%s) + +CURRENT="None (before Fajr)" +NEXT="" +NEXT_TIME="" +NEXT_EPOCH=0 +LAST="" + +for i in "${!PRAYER_NAMES[@]}"; do + name="${PRAYER_NAMES[$i]}" + time="${PRAYER_TIMES[$i]}" + ep=$(epoch_today "$time") + + if [ $ep -le $NOW ]; then + LAST=$name + elif [ -z "$NEXT" ]; then + NEXT=$name + NEXT_TIME=$time + NEXT_EPOCH=$ep + fi +done + +if [ -n "$LAST" ]; then + CURRENT="$LAST" +fi + +# After Isha → next is tomorrow Fajr +if [ -z "$NEXT" ]; then + NEXT="Fajr (tomorrow)" + NEXT_TIME="$FAJR" + NEXT_EPOCH=$(( $(epoch_today "$FAJR") + 86400 )) +fi + +DIFF=$(( NEXT_EPOCH - NOW )) +H=$(( DIFF / 3600 )) +M=$(( (DIFF % 3600) / 60 )) +COUNTDOWN="${H}h ${M}m" + +NEXT_AM=$(to_ampm "$NEXT_TIME") + +# ANSI color codes +GREEN=$'\033[32m' +YELLOW=$'\033[33m' +RESET=$'\033[0m' + +# Color code current prayer (green) +CURRENT_DISPLAY="${GREEN}${CURRENT}${RESET}" + +# Color code countdown yellow if less than 10 minutes +if [ $DIFF -lt 600 ]; then + COUNTDOWN_DISPLAY="${YELLOW}${COUNTDOWN}${RESET}" +else + COUNTDOWN_DISPLAY="$COUNTDOWN" +fi + +echo "Current: $CURRENT_DISPLAY | Next: $NEXT at $NEXT_AM in $COUNTDOWN_DISPLAY" From 195dda40e2213a96433374f5c611a6f8e15e09ab Mon Sep 17 00:00:00 2001 From: Muneeb Date: Thu, 27 Nov 2025 01:59:31 +0500 Subject: [PATCH 2/3] Rename prayer-summary.sh to prayer-summary.template.sh --- .../culture/{prayer-summary.sh => prayer-summary.template.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename commands/culture/{prayer-summary.sh => prayer-summary.template.sh} (100%) diff --git a/commands/culture/prayer-summary.sh b/commands/culture/prayer-summary.template.sh similarity index 100% rename from commands/culture/prayer-summary.sh rename to commands/culture/prayer-summary.template.sh From 977ae63d7432ecb4fab287f7b493dd271abfc50f Mon Sep 17 00:00:00 2001 From: Muneeb Date: Thu, 27 Nov 2025 01:59:36 +0500 Subject: [PATCH 3/3] Add template configuration, dependencies, and author metadata --- commands/culture/prayer-summary.template.sh | 114 ++++++++++++-------- 1 file changed, 68 insertions(+), 46 deletions(-) diff --git a/commands/culture/prayer-summary.template.sh b/commands/culture/prayer-summary.template.sh index 8957bb654..6388fd930 100644 --- a/commands/culture/prayer-summary.template.sh +++ b/commands/culture/prayer-summary.template.sh @@ -1,47 +1,84 @@ #!/bin/bash +# How to use this script? +# It's a template which needs further setup. Duplicate the file, +# remove `.template.` from the filename and set your city and country below. +# Optionally, adjust the calculation method to fit your location. +# +# API: https://aladhan.com/prayer-times-api + +# Dependency: This script requires `jq` cli installed: https://stedolan.github.io/jq/ +# Install via homebrew: `brew install jq` + # Required parameters: # @raycast.schemaVersion 1 # @raycast.title Prayer Summary -# @raycast.description Get the prayer times for the current day # @raycast.mode inline # @raycast.refreshTime 2m # Optional parameters: # @raycast.icon 🕌 +# @raycast.packageName Culture + +# Documentation: +# @raycast.description Get the current and next prayer times for a specific city and country. +# @raycast.author Muneeb Ajaz +# @raycast.authorURL https://github.com/mianmuneebajaz + + +# Configuration + +# Set your city and country below: +# 1. Replace CITY with your city name (e.g., "London") +# 2. Replace COUNTRY with your country name (e.g., "United Kingdom") +CITY="" +COUNTRY="" + +# Calculation method (default: 3 for Muslim World League - MWL) +# Common methods: +# 1 - University of Islamic Sciences, Karachi +# 2 - Islamic Society of North America (ISNA) +# 3 - Muslim World League (MWL) +# 4 - Umm Al-Qura University, Makkah +# 5 - Egyptian General Authority of Survey +# See https://aladhan.com/prayer-times-api for all methods +METHOD="3" + + +# Main program -CITY="Lahore" -COUNTRY="Pakistan" -METHOD=13 +if ! command -v jq &> /dev/null; then + echo "jq is required (https://stedolan.github.io/jq/)" + exit 1 +fi + +if [ -z "$CITY" ] || [ -z "$COUNTRY" ]; then + echo "City and Country are required" + exit 1 +fi -DATA=$(curl -s -L "http://api.aladhan.com/v1/timingsByCity?city=$CITY&country=$COUNTRY&method=$METHOD") +DATA=$(curl -s -L "http://api.aladhan.com/v1/timingsByCity?city=${CITY}&country=${COUNTRY}&method=${METHOD}") if [ -z "$DATA" ]; then - echo "⚠️ Error: Unable to fetch prayer times" - exit 0 + echo "Unable to fetch prayer times" + exit 1 fi get_time() { echo "$DATA" | jq -r ".data.timings.$1" } -FAJR=$(get_time Fajr) -DHUHR=$(get_time Dhuhr) -ASR=$(get_time Asr) -MAGHRIB=$(get_time Maghrib) -ISHA=$(get_time Isha) +FAJR=$(get_time "Fajr") +DHUHR=$(get_time "Dhuhr") +ASR=$(get_time "Asr") +MAGHRIB=$(get_time "Maghrib") +ISHA=$(get_time "Isha") -# Convert 24h → 12h format +# Convert 24h to 12h format to_ampm() { date -j -f "%H:%M" "$1" "+%I:%M %p" 2>/dev/null } -FAJR_AM=$(to_ampm "$FAJR") -DHUHR_AM=$(to_ampm "$DHUHR") -ASR_AM=$(to_ampm "$ASR") -MAGHRIB_AM=$(to_ampm "$MAGHRIB") -ISHA_AM=$(to_ampm "$ISHA") - PRAYER_NAMES=("Fajr" "Dhuhr" "Asr" "Maghrib" "Isha") PRAYER_TIMES=("$FAJR" "$DHUHR" "$ASR" "$MAGHRIB" "$ISHA") @@ -62,12 +99,12 @@ for i in "${!PRAYER_NAMES[@]}"; do time="${PRAYER_TIMES[$i]}" ep=$(epoch_today "$time") - if [ $ep -le $NOW ]; then - LAST=$name + if [ "$ep" -le "$NOW" ]; then + LAST="$name" elif [ -z "$NEXT" ]; then - NEXT=$name - NEXT_TIME=$time - NEXT_EPOCH=$ep + NEXT="$name" + NEXT_TIME="$time" + NEXT_EPOCH="$ep" fi done @@ -75,33 +112,18 @@ if [ -n "$LAST" ]; then CURRENT="$LAST" fi -# After Isha → next is tomorrow Fajr +# After Isha, next prayer is tomorrow's Fajr if [ -z "$NEXT" ]; then NEXT="Fajr (tomorrow)" NEXT_TIME="$FAJR" - NEXT_EPOCH=$(( $(epoch_today "$FAJR") + 86400 )) -fi + NEXT_EPOCH=$(($(epoch_today "$FAJR") + 86400)) +fi -DIFF=$(( NEXT_EPOCH - NOW )) -H=$(( DIFF / 3600 )) -M=$(( (DIFF % 3600) / 60 )) +DIFF=$((NEXT_EPOCH - NOW)) +H=$((DIFF / 3600)) +M=$(((DIFF % 3600) / 60)) COUNTDOWN="${H}h ${M}m" NEXT_AM=$(to_ampm "$NEXT_TIME") -# ANSI color codes -GREEN=$'\033[32m' -YELLOW=$'\033[33m' -RESET=$'\033[0m' - -# Color code current prayer (green) -CURRENT_DISPLAY="${GREEN}${CURRENT}${RESET}" - -# Color code countdown yellow if less than 10 minutes -if [ $DIFF -lt 600 ]; then - COUNTDOWN_DISPLAY="${YELLOW}${COUNTDOWN}${RESET}" -else - COUNTDOWN_DISPLAY="$COUNTDOWN" -fi - -echo "Current: $CURRENT_DISPLAY | Next: $NEXT at $NEXT_AM in $COUNTDOWN_DISPLAY" +echo "Current: $CURRENT | Next: $NEXT at $NEXT_AM in $COUNTDOWN"