From 07bac5b791503a639149c920bc4762e7e6ec7adc Mon Sep 17 00:00:00 2001 From: Flinner Date: Mon, 28 Oct 2024 19:07:50 +0300 Subject: [PATCH] Add auto fetching of latitude/longitude --- .local/bin/prayer-times | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.local/bin/prayer-times b/.local/bin/prayer-times index caf3793..d625b5f 100755 --- a/.local/bin/prayer-times +++ b/.local/bin/prayer-times @@ -2,6 +2,7 @@ # ----- Parameters ------ # # Coordinates: https://www.mapcoordinates.net/en +# Set lat and long explicitly, or leave commented to get them automatically from ipinfo.io lat='30.001780' long='31.290419' # Calculation Method: https://api.aladhan.com/v1/methods @@ -49,12 +50,29 @@ check() { fi if [[ "$fetch_prayers" || "$available_month" != "${date[month]}" ]]; then + # Fetch the geolocation data from ipinfo.io + response=$(curl -s https://ipinfo.io) + + echo "-- fetching latitude and longitude" + # Parse the latitude and longitude + location=$(echo $response | jq -r '.loc') + + # Separate latitude and longitude + latitude=$(echo $location | cut -d',' -f1) + longitude=$(echo $location | cut -d',' -f2) + + # Set `lat` to `latitude`, or default to the specified value above + lat=${latitude:lat} + long=${longitude:long} + + echo "-- latitude: ${lat}, longitude: ${long}" echo "-- fetching current month prayer calendar (${date[month]}-${date[year]})" # Documentation: https://aladhan.com/prayer-times-api#GetCalendar curl -Lso "$prayers_json" "https://api.aladhan.com/v1/calendar/${date[year]}/${date[month]}?latitude=$lat&longitude=$long&method=$method" fi } + add-jobs() { # WARNING: THIS SCRIPTS REMOVES ALL JOBS IN QUEUE "P" SCHEDULED USING AT (ADJUST ACCORDINGLY) echo "-- removing all jobs in queue 'p'"