Muslim prayer times command

Hey, so I have a json code for Muslim prayer times that I get from an API url http://api.aladhan.com/v1/timings/$(time Africa/Cairo "DD MM YYYY")?latitude=30.053733&longitude=31.338610&method=5, how can I filter out it’s data to only get those 5 times Fajr: 03:25 AM | Dhuhr: 11:51 AM | Asr: 03:28 PM | Maghrib: 06:39 PM | Isha: 08:06 PM is it possible to even transfer 24 hour into 12 hour without it being originally in the code?

{
    "code": 200,
    "status": "OK",
    "data": {
        "timings": {
            "Fajr": "03:25",
            "Sunrise": "05:03",
            "Dhuhr": "11:51",
            "Asr": "15:28",
            "Sunset": "18:39",
            "Maghrib": "18:39",
            "Isha": "20:06",
            "Imsak": "03:15",
            "Midnight": "23:51"
        },
        "date": {
            "readable": "12 May 2022",
            "timestamp": "1652342672",
            "hijri": {
                "date": "10-10-1443",
                "format": "DD-MM-YYYY",
                "day": "10",
                "weekday": {
                    "en": "Al Khamees",
                    "ar": "\u0627\u0644\u062e\u0645\u064a\u0633"
                },
                "month": {
                    "number": 10,
                    "en": "Shaww\u0101l",
                    "ar": "\u0634\u064e\u0648\u0651\u0627\u0644"
                },
                "year": "1443",
                "designation": {
                    "abbreviated": "AH",
                    "expanded": "Anno Hegirae"
                },
                "holidays": []
            },
            "gregorian": {
                "date": "12-05-2022",
                "format": "DD-MM-YYYY",
                "day": "12",
                "weekday": {
                    "en": "Thursday"
                },
                "month": {
                    "number": 5,
                    "en": "May"
                },
                "year": "2022",
                "designation": {
                    "abbreviated": "AD",
                    "expanded": "Anno Domini"
                }
            }
        },
        "meta": {
            "latitude": 30.053733,
            "longitude": 31.33861,
            "timezone": "Africa\/Cairo",
            "method": {
                "id": 5,
                "name": "Egyptian General Authority of Survey",
                "params": {
                    "Fajr": 19.5,
                    "Isha": 17.5
                },
                "location": {
                    "latitude": 30.0444196,
                    "longitude": 31.2357116
                }
            },
            "latitudeAdjustmentMethod": "ANGLE_BASED",
            "midnightMode": "STANDARD",
            "school": "STANDARD",
            "offset": {
                "Imsak": 0,
                "Fajr": 0,
                "Sunrise": 0,
                "Dhuhr": 0,
                "Asr": 0,
                "Maghrib": 0,
                "Sunset": 0,
                "Isha": 0,
                "Midnight": 0
            }
        }
    }
}

Hey @karimawi!

It couldn’t be easier! With JSON you move up the keys tree using dots.

$(eval a = $(urlfetch json http://api.aladhan.com/v1/timings/$(time Africa/Cairo "DD-MM-YYYY")?latitude=30.053733&longitude=31.338610&method=5); if (a.code === 200) {t = a.data.timings; `Fajr: ${t.Fajr} | Dhuhr: ${t.Dhuhr} | Asr: ${t.Asr} | Maghrib: ${t.Maghrib} | Isha: ${t.Isha}`} else {'There was an error'})

To convert the timing from a 24h format to 12h it requires a bit more code and gymnastics:

$(eval a = $(urlfetch json http://api.aladhan.com/v1/timings/$(time Africa/Cairo "DD-MM-YYYY")?latitude=30.053733&longitude=31.338610&method=5); if (a.code === 200) {t = a.data.timings; Object.keys(t).map(e => {d = t[e].split(':'); h = (d[0] % 12) || 12; t[e] = `${h}:${d[1]} ${h == d[0] ? 'AM' : 'PM'}`;}); `Fajr: ${t.Fajr} | Dhuhr: ${t.Dhuhr} | Asr: ${t.Asr} | Maghrib: ${t.Maghrib} | Isha: ${t.Isha}`} else {'There was an error'})

Get the prayer times for the next day.

1 Like

THANK YOU VERY MUCH, you’re a life saver <3

1 Like