abdulrahman.id icon indicating copy to clipboard operation
abdulrahman.id copied to clipboard

Daily Prayer Time

Open abdulrcs opened this issue 2 months ago • 0 comments


slug: daily-prayer-time date: 17-Jan-2021 summary: An easy-to-use API to get today’s prayer time based on Muslim Pro techStack: Python, Flask category: Personal Project githubLink: https://github.com/abdulrcs/Daily-Prayer-Time-API image: https://github.com/abdulrcs/abdulrahman.id/assets/54136956/4d46f56d-ed51-46c5-9b4f-1b110968935e

Overview

It's an easy-to-use API to get today's (and tomorrow!) prayer time for your next project! (based on Muslim Pro)

Project Goals

This API was actually written because of my personal use case, it was holiday season at the time and I wanted to maximize those online gaming sessions with my friends, we all know online games (like Valorant) can't be paused mid-match, so I built an API for my personal Discord bot to know how much session we can play before the next prayer time.

But I published the API for general use cases for many people by providing a smooth way to integrate prayer times into their projects 🎉

Tech Stack

Written in Python using Flask, Beautiful Soup, and duckduckgo_search.

Features ✨

API Response

{
  "city": "Mecca",
  "date": "25 March 2021",
  "today": {
    "Fajr": "05:04",
    "Sunrise": "06:20",
    "Dhuhr": "12:27",
    "Asr": "15:52",
    "Maghrib": "18:34",
    "Isha'a": "20:04"
  },
  "tomorrow": {
    "Date": "Fri 26 Mar",
    "Fajr": "05:03",
    "Sunrise": "06:19",
    "Dhuhr": "12:27",
    "Asr": "15:52",
    "Maghrib": "18:34",
    "Isha'a": "20:04"
  }
}

Challenges

There's a lot of complexities when you're doing web scraping.

My initial approach involved querying the Muslim Pro website directly for prayer times in various cities. However, this is ineffective because the URLs of the prayer time from each city are different and may involve the language of that city in the URL.

To address that issue, I had an idea of using a search engine, I can get the most relevant site by querying (city) prayer time site:muslimpro.com I can safely query any city in the world while making sure it's a valid Muslim Pro URL that way.

Then, the most inevitable problem of web scraping is the changes in the source website, Muslim Pro site has several HTML structure revisions, and I have to adjust and even rewrite the code at times.

Learning and Takeaways

This project turned out to be a win-win, because not only did I get to hone my coding skills by learning web scraping with Python, but I also created something that can be useful for others, the numerous thank-you notes to my email regarding this project were truly heartwarming.

It was the first time something I coded actually got used by other people, I still remember the first email I got and it really made my day :')

abdulrcs avatar Apr 16 '24 14:04 abdulrcs