Skip to main content

An offline library calculating prayer times

Project description

adhanpy

License: MIT pytest

This is a port of batoulapps/adhan-java, a prayer times program, from Java to Python. As it stands the project reuses most of the structure of the original project but may differ through refactoring and in an effort to rewrite in a more pythonic way where it makes sense. Like the original project there are no external dependencies except in development where pytest and other development tools are made use of.

Requirements

  • Python >= 3.9

Installation

pip install adhanpy

Usage

Create a PrayerTimes object by passing geo coodinates, datetime and either passing a calculation method:

prayer_times = PrayerTimes(coordinates, today, CalculationMethod.MOON_SIGHTING_COMMITTEE)

or a calculation parameters object allowing to choose from different parameters such as angles:

parameters = CalculationParameters(fajr_angle=18, isha_angle=18)
prayer_times = PrayerTimes(coordinates, today, calculation_parameters=parameters)

If passing a calculation method to the calculation parameters object, the calculation method will have precedence and will overwrite other parameters you may have also passed.

For instance the MOON_SIGHTING_COMMITTEE method uses a fajr angle of 18 and if for instance the calculation parameters object is created by passing a different fajr angle the latter will be ignored:

parameters = CalculationParameters(fajr_angle=12, method=CalculationMethod.MOON_SIGHTING_COMMITTEE)
prayer_times = PrayerTimes(coordinates, today, calculation_parameters=parameters)
print(parameters.fajr_angle)
# 18.0 (the fajr_angle argument has been ignored)

Times are returned in UTC time via datetime objects, for convenience it is possible to directly pass a ZoneInfo object to PrayerTimes:

london_zone = ZoneInfo("Europe/London")
prayer_times = PrayerTimes(
    coordinates,
    today,
    CalculationMethod.MOON_SIGHTING_COMMITTEE,
    time_zone=london_zone,
)

# this will display the time in the chosen time zone
print(f"Fajr: {prayer_times.fajr.strftime('%H:%M')}")

or convert to a different timezone later, each prayer time object is in fact a datetime object:

prayer_times = PrayerTimes(
    coordinates,
    today,
    CalculationMethod.MOON_SIGHTING_COMMITTEE,
)

# the following will be in UTC
print(f"Fajr: {prayer_times.fajr.strftime('%H:%M')}")

# and to use a different timezone on the datetime object itself:
london_zone = ZoneInfo("Europe/London")
print(f"Fajr: {prayer_times.fajr.astimezone(london_zone).strftime('%H:%M')}")

A full example is located in src/example of the project directory.

Development

To install adhanpy for development purposes, run the following:

python3 -m virtualenv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
pip install -e .

Licence

MIT

Acknowledgments

Credits go to the author of the original implementation in Java and other languages, especially the very complex astronomy formulas.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

adhanpy-1.0.5.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

adhanpy-1.0.5-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file adhanpy-1.0.5.tar.gz.

File metadata

  • Download URL: adhanpy-1.0.5.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for adhanpy-1.0.5.tar.gz
Algorithm Hash digest
SHA256 9b6670f8d563d61d4f9fde581165cbe692c917710b694cb6b5e2130ffc902680
MD5 bba4592a6b228fd501fa1a791c87e2c3
BLAKE2b-256 82771111dd754493146e14d4a28ac4df114cc5c74b4317055a300dd5df3df1bf

See more details on using hashes here.

File details

Details for the file adhanpy-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: adhanpy-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for adhanpy-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 79d765e6b91d3b29448988691957b51109faaca10f498eb3656e7c87b56b6066
MD5 34a1ff1f038124897bd86f93f2b6817c
BLAKE2b-256 365b89b9705b95aca620409574ce4bd4e013c33d3fd1f27edf7ab9b9ca40a18c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page