directorium
directorium
A wrapper package for the public API of https://eucharistiefeier.de/lk/. It is able to provide information from the liturgical calendar such as liturgical color and lectures. To start with the package just run:
pip install directorium
Getting started
A sample usage would be:
from datetime import date
from directorium import Directorium
directorium = Directorium.from_request()
today = date.today()
events = directorium.get(today)
print(events)
Documentation
An automatically created documentation is available on the GitHub Pages of this project.
Contributing
You're more than invited to contribute to this project. Any kind of help is appreciated. Just open an issue or a pull request.
- Fork the project
- Add a python environment with
python -m venv .venv
- Activate the environment with
source .venv/bin/activate
- Install the development dependencies with
pip install -e .[development]
- Install the pre-commit hooks with
pre-commit install
- Create a new branch
- Make your changes (remember to add tests!) and commit them
- Install the test dependencies with
pip install -e .[test]
- Run the tests with
pytest
- Push your changes and open a pull request
Acknowledgments
Thanks a lot to the Salesians of Don Bosco for providing the API!
License
Released under MIT by @matthiasgi.
42class Directorium: 43 """The main class to access the liturgical calendar. 44 45 The API-backend is exchangeable to allow for different sources of the 46 liturgical calendar data. 47 48 Attributes: 49 api (Api): The API to get the liturgical events from. 50 """ 51 52 def __init__(self, api: Api): 53 """Creates the Directorium with the given API. 54 55 Args: 56 api (Api): The api to get the liturgical events from. 57 """ 58 self.api = api 59 60 def get(self, d: Optional[date] = None) -> List[Event]: 61 """Retrieves a list of liturgical events for a specific date. 62 63 Args: 64 d (Optional[date]): The date for which to get the liturgical events. 65 If None is provided, the current date is used. Defaults to None. 66 67 Returns: 68 List[Event]: List of liturgical events for the given date. 69 """ 70 if d is None: 71 d = date.today() 72 return [Event.parse(e) for e in self.api.get_date(d)] 73 74 @deprecated("Use static method `get_season` instead.") 75 def season(self, d: Optional[date] = None) -> Season: 76 """Determines the season of the liturgical year for a specific date. 77 78 Args: 79 d (Optional[date]): The date for which to determine the season. If 80 None is provided, the current date is used. Defaults to None. 81 82 Returns: 83 Season: The season of the liturgical year for the given date. 84 """ 85 return Directorium.get_season(d) 86 87 @staticmethod 88 def get_season(d: Optional[date] = None) -> Season: 89 """Determines the season of the liturgical year for a specific date. 90 91 Args: 92 d (Optional[date]): The date for which to determine the season. If 93 None is provided, the current date is used. Defaults to None. 94 95 Returns: 96 Season: The season of the liturgical year for the given date. 97 """ 98 if d is None: 99 d = date.today() 100 christmas = date(d.year, 12, 25) 101 advent = christmas - timedelta(days=21 + christmas.isoweekday()) 102 if d >= advent: 103 return Season.CHRISTMAS 104 105 epiphany = date(d.year, 1, 6) 106 baptism = epiphany + timedelta(days=7 - epiphany.isoweekday() % 7) 107 if d <= baptism: 108 return Season.CHRISTMAS 109 110 easter = utils.easter(d.year) 111 ashwednesday = easter - timedelta(days=46) 112 if d >= ashwednesday and d < easter: 113 return Season.LENT 114 115 pentecoste = easter + timedelta(days=49) 116 if d >= easter and d < pentecoste: 117 return Season.EASTER 118 119 return Season.ORDINARY 120 121 @staticmethod 122 def from_request(calendar: str | None = None) -> "Directorium": 123 """Creates a Directorium instance with a `RequestApi` backend. 124 125 Args: 126 calendar (str | None, optional): The name of the calendar to use. 127 128 Returns: 129 Directorium: The Directorium instance with a RequestApi backend. 130 """ 131 from .api import RequestApi 132 return Directorium(RequestApi(calendar)) 133 134 @staticmethod 135 def from_file(format_path: str) -> "Directorium": 136 """Creates a Directorium instance with a `FileApi` backend. 137 138 Args: 139 format_path (str): The format string for the file path. 140 141 Returns: 142 Directorium: The Directorium instance with a FileApi backend. 143 """ 144 from .api import FileApi 145 return Directorium(FileApi(format_path)) 146 147 @staticmethod 148 def from_cache(base_path: str | None = None, calendar: str | None = None) -> "Directorium": 149 """Creates a Directorium instance with a `CacheApi` backend. 150 151 Args: 152 base_path (str | None, optional): The base path for the cache files. 153 If None, the default folder defined in `CacheApi` is used. 154 calendar (str | None, optional): The name of the calendar to use. 155 156 Returns: 157 Directorium: The Directorium instance with a CacheApi backend. 158 """ 159 from .api import CacheApi 160 return Directorium(CacheApi(base_path, calendar))
The main class to access the liturgical calendar.
The API-backend is exchangeable to allow for different sources of the liturgical calendar data.
Attributes:
- api (Api): The API to get the liturgical events from.
52 def __init__(self, api: Api): 53 """Creates the Directorium with the given API. 54 55 Args: 56 api (Api): The api to get the liturgical events from. 57 """ 58 self.api = api
Creates the Directorium with the given API.
Arguments:
- api (Api): The api to get the liturgical events from.
60 def get(self, d: Optional[date] = None) -> List[Event]: 61 """Retrieves a list of liturgical events for a specific date. 62 63 Args: 64 d (Optional[date]): The date for which to get the liturgical events. 65 If None is provided, the current date is used. Defaults to None. 66 67 Returns: 68 List[Event]: List of liturgical events for the given date. 69 """ 70 if d is None: 71 d = date.today() 72 return [Event.parse(e) for e in self.api.get_date(d)]
Retrieves a list of liturgical events for a specific date.
Arguments:
- d (Optional[date]): The date for which to get the liturgical events. If None is provided, the current date is used. Defaults to None.
Returns:
List[Event]: List of liturgical events for the given date.
74 @deprecated("Use static method `get_season` instead.") 75 def season(self, d: Optional[date] = None) -> Season: 76 """Determines the season of the liturgical year for a specific date. 77 78 Args: 79 d (Optional[date]): The date for which to determine the season. If 80 None is provided, the current date is used. Defaults to None. 81 82 Returns: 83 Season: The season of the liturgical year for the given date. 84 """ 85 return Directorium.get_season(d)
Determines the season of the liturgical year for a specific date.
Arguments:
- d (Optional[date]): The date for which to determine the season. If None is provided, the current date is used. Defaults to None.
Returns:
Season: The season of the liturgical year for the given date.
87 @staticmethod 88 def get_season(d: Optional[date] = None) -> Season: 89 """Determines the season of the liturgical year for a specific date. 90 91 Args: 92 d (Optional[date]): The date for which to determine the season. If 93 None is provided, the current date is used. Defaults to None. 94 95 Returns: 96 Season: The season of the liturgical year for the given date. 97 """ 98 if d is None: 99 d = date.today() 100 christmas = date(d.year, 12, 25) 101 advent = christmas - timedelta(days=21 + christmas.isoweekday()) 102 if d >= advent: 103 return Season.CHRISTMAS 104 105 epiphany = date(d.year, 1, 6) 106 baptism = epiphany + timedelta(days=7 - epiphany.isoweekday() % 7) 107 if d <= baptism: 108 return Season.CHRISTMAS 109 110 easter = utils.easter(d.year) 111 ashwednesday = easter - timedelta(days=46) 112 if d >= ashwednesday and d < easter: 113 return Season.LENT 114 115 pentecoste = easter + timedelta(days=49) 116 if d >= easter and d < pentecoste: 117 return Season.EASTER 118 119 return Season.ORDINARY
Determines the season of the liturgical year for a specific date.
Arguments:
- d (Optional[date]): The date for which to determine the season. If None is provided, the current date is used. Defaults to None.
Returns:
Season: The season of the liturgical year for the given date.
121 @staticmethod 122 def from_request(calendar: str | None = None) -> "Directorium": 123 """Creates a Directorium instance with a `RequestApi` backend. 124 125 Args: 126 calendar (str | None, optional): The name of the calendar to use. 127 128 Returns: 129 Directorium: The Directorium instance with a RequestApi backend. 130 """ 131 from .api import RequestApi 132 return Directorium(RequestApi(calendar))
Creates a Directorium instance with a RequestApi
backend.
Arguments:
- calendar (str | None, optional): The name of the calendar to use.
Returns:
Directorium: The Directorium instance with a RequestApi backend.
134 @staticmethod 135 def from_file(format_path: str) -> "Directorium": 136 """Creates a Directorium instance with a `FileApi` backend. 137 138 Args: 139 format_path (str): The format string for the file path. 140 141 Returns: 142 Directorium: The Directorium instance with a FileApi backend. 143 """ 144 from .api import FileApi 145 return Directorium(FileApi(format_path))
Creates a Directorium instance with a FileApi
backend.
Arguments:
- format_path (str): The format string for the file path.
Returns:
Directorium: The Directorium instance with a FileApi backend.
147 @staticmethod 148 def from_cache(base_path: str | None = None, calendar: str | None = None) -> "Directorium": 149 """Creates a Directorium instance with a `CacheApi` backend. 150 151 Args: 152 base_path (str | None, optional): The base path for the cache files. 153 If None, the default folder defined in `CacheApi` is used. 154 calendar (str | None, optional): The name of the calendar to use. 155 156 Returns: 157 Directorium: The Directorium instance with a CacheApi backend. 158 """ 159 from .api import CacheApi 160 return Directorium(CacheApi(base_path, calendar))
Creates a Directorium instance with a CacheApi
backend.
Arguments:
- base_path (str | None, optional): The base path for the cache files.
If None, the default folder defined in
CacheApi
is used. - calendar (str | None, optional): The name of the calendar to use.
Returns:
Directorium: The Directorium instance with a CacheApi backend.