Skip to content

Instantly share code, notes, and snippets.

@Minemobs
Last active April 1, 2024 15:20
Show Gist options
  • Save Minemobs/0380bcec9c25466adce9e445f1bc9fb8 to your computer and use it in GitHub Desktop.
Save Minemobs/0380bcec9c25466adce9e445f1bc9fb8 to your computer and use it in GitHub Desktop.
A simple mawaqit parser in bash
#!/bin/bash
CURL_RES=$(printf "{%s}\n" $(curl -s https://mawaqit.net/fr/champigny94500 | grep -P '"times":\[["\d:,]+\]' --only-matching))
function getDiffUnit {
echo "scale=2 ; $(( $(date -d "$(echo "$CURL_RES" | jq .times["$1"] | cut -d '"' -f 2)" "+%s") - $(date "+%s") ))/$2" | bc
}
function getDiff {
getDiffUnit "$1" 3600
}
FAJR=$(echo "$CURL_RES" | jq .times[0] | cut -d '"' -f 2)
DHUHR=$(echo "$CURL_RES" | jq .times[1] | cut -d '"' -f 2)
ASR=$(echo "$CURL_RES" | jq .times[2] | cut -d '"' -f 2)
MAGHRIB=$(echo "$CURL_RES" | jq .times[3] | cut -d '"' -f 2)
ISHA=$(echo "$CURL_RES" | jq .times[4] | cut -d '"' -f 2)
printf "Current time: %s\n" "$(date +"%H:%M:%S")"
printf "Fajr: %s\nDhuhr: %s\nAsr: %s\nMaghrib: %s\nIsha: %s\n" "$FAJR" "$DHUHR" "$ASR" "$MAGHRIB" "$ISHA"
prayer_names=("Fajr" "Dhuhr" "Asr" "Maghrib" "Isha")
array=("$(getDiff 0)" "$(getDiff 1)" "$(getDiff 2)" "$(getDiff 3)" "$(getDiff 4)")
for i in "${!array[@]}"; do
str=${array[i]}
if [[ $str == -* ]]; then
continue
fi
if [[ $str == .* ]]; then
minutesDiff=$(getDiffUnit "$i" 60)
if [[ $minutesDiff == .* ]]; then
printf "%s in %s seconds" "${prayer_names[i]}" "$(getDiffUnit "$i" 1 | cut -d . -f 1)"
else
printf "%s in %s minutes" "${prayer_names[i]}" "$(echo "$minutesDiff" | cut -d . -f 1)"
fi
else
printf "%s in %s hours" "${prayer_names[i]}" "$(echo "$str" | cut -d . -f 1)"
fi
break
done
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment