Skip to main content

Moroccan Prayer Times CLI

PyPI - Version PyPI - Python Version GitHub License

A command-line interface (CLI) application to fetch and display Moroccan prayer times for the current day or the next prayer time remaining. The data comes, by default, from the official Moroccan Ministry of Habous and Islamic Affairs website, and other providers can be selected.

Features

  • Display today's prayer times for a selected Moroccan city
  • Show the time remaining until the next prayer
  • Configure the preferred city, language and prayer times provider
  • Pluggable prayer times providers (Habous and Aladhan included)
  • Caching the fetched prayer times for better performance
  • Localization support for Arabic, English, and French languages

Installation

You can install the package using either pipx or pip.

Note: It is highly recommended to install this package using pipx. It provides an isolated environment for installing and managing command-line tools. It also simplifies running CLIs without activating a virtual environment.
Check out this page to compare pip and pipx.

Using pipx

pipx install moroccan-prayer-times

Using pip

pip install moroccan-prayer-times

Usage

After the installation, you can run the CLI application with the following command:

prayertime help

This will display the list of available commands and their descriptions.

Commands

  • prayertime next: Show the remaining time until the next prayer.
  • prayertime today: Display today's prayer times for the configured city.
  • prayertime config: Display the current configuration (city, language, provider and past prayer display).
  • prayertime setup: Configure the preferred city, language, provider and past prayer display.
  • prayertime help: Show the help message.

Note: the default command is next.

Configuration

The first time you run the application, it will prompt you to select a city (english is the default language). These settings will be saved for future use.

You can change the city, the language or the provider anytime using the setup command.

Past prayer display

By default, prayertime next only shows the upcoming prayer. You can also have it remind you of a prayer that has just passed, for a number of minutes between 1 and 20:

  Al-Asr was 3 minute(s) ago
  Al-Maghrib at 17:47 => 2 hour(s) and 24 minute(s) left

It is disabled by default. Enable, change or disable it with prayertime setup, or by editing the past_prayer_minutes entry of the config file (remove it to disable the feature).

Providers

A provider is the source of the prayer times. The provider is part of the config and defaults to habous.

Provider Source
habous habous.gov.ma (default)
aladhan api.aladhan.com (method 21, Morocco), limited to a subset of the cities

Aladhan finds a city by its name and cannot resolve many small towns, so aladhan only offers the cities that were verified to work (scripts/check_aladhan_cities.sh and scripts/reverify_aladhan_cities.sh re-check them). If your saved city isn't available when you switch to it, setup asks you to pick another one.

Choose it with prayertime setup, or by editing the provider entry of the config file. The PRAYERTIME_PROVIDER environment variable overrides the saved value, which is handy for a one-off run:

PRAYERTIME_PROVIDER=aladhan prayertime today

Adding a provider

A provider is a subclass of PrayerTimesProvider (moroccan_prayer_times/providers/base.py). It only has to define:

  • name: the identifier used in the config,
  • description (optional): a short sentence displayed next to the name when choosing a provider in setup,
  • get_cities(): the available cities ({id: name}),
  • fetch_prayer_times(city_id): today's six times (Fajr, Sunrise, Dhuhr, Asr, Maghrib, Isha) as "HH:MM".

The today and next commands are implemented by the base class on top of those (with a per-day cache), and can be overridden if a provider needs something different.

from moroccan_prayer_times.providers import PrayerTimesProvider, register


@register
class MyProvider(PrayerTimesProvider):
    name = "my-provider"

    def get_cities(self):
        return {1: "Rabat"}

    def fetch_prayer_times(self, city_id):
        return {"Fajr": "05:03", "Sunrise": "06:31", "Dhuhr": "12:12",
                "Asr": "15:17", "Maghrib": "17:47", "Isha": "19:01"}

Inside this package, put the class in a new module of moroccan_prayer_times/providers/ named like the provider (e.g. aladhan.py for aladhan) and decorate it with @register: it is found automatically, and only imported when it is selected.

From an external package, declare it as an entry point instead and it will be discovered automatically:

# setup.py of the plugin
entry_points={"moroccan_prayer_times.providers": ["my-provider = my_package.module:MyProvider"]}

City ids are the ones of the Habous website; they are shared by all the providers, which map them to their own cities.

NOTE: If you choose to use the Arabic language option with this package, make sure to check the following:

  1. Terminal Encoding: Ensure that your terminal is configured to use UTF-8 or another encoding that supports Arabic characters. In some terminals or IDEs (like PyCharm), you may need to set the encoding explicitly.

  2. Font Support: Verify that your system has fonts installed that support the display of Arabic characters. Without proper font support, Arabic text may not render correctly.

Contributing

To run the tests:

pip install -r requirements.txt -r requirements-dev.txt
python -m pytest tests

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.

License

This project is licensed under the MIT License.

Contact

If you have any questions or suggestions, feel free to contact me at ismailben44@gmail.com.

Metadata

Release files for moroccan-prayer-times 2.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for moroccan-prayer-times 2.1.1
File Size Uploaded Provenance
moroccan_prayer_times-2.1.1.tar.gz 28.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for moroccan-prayer-times 2.1.1
File Interpreter ABI Platform
moroccan_prayer_times-2.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 53.7 kB

Release files / moroccan_prayer_times-2.1.1.tar.gz

Download URL moroccan_prayer_times-2.1.1.tar.gz
Size 28.4 kB
Tags Source
SHA-256 checksum
How to use checksums
210d2a9efc1f21e2f889d3d97e62330717be03ed7b314422542664851b9ddea4
BLAKE2b-256 checksum
How to use checksums
b851a40441e23e713628e0b3c63988433c78b2087d219d31e02a01c58a75b8aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Release files / moroccan_prayer_times-2.1.1-py3-none-any.whl

Download URL moroccan_prayer_times-2.1.1-py3-none-any.whl
Size 25.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7bf66dd7d230b0b87a6be2c4b987dd4ad5c898e723aa6376dce09fd272445368
BLAKE2b-256 checksum
How to use checksums
600813e9444258248ff04fee676f62f429d3828ec7d603b9f38024506119de33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Security for moroccan-prayer-times 2.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page