Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto fetching of latitude/longitude #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .local/bin/prayer-times
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'"
Expand Down