liturgical-app / calendar

Library to determine liturgical dates and colours for the Anglican Church of England
4 stars 0 forks source link

Colour code not returned on some dates. #1

Closed togster closed 8 months ago

togster commented 8 months ago

Sometimes the dict returned by the library doesn't have a colourcode key. The following code gives all of the dates for 2024.

from datetime import date
from dateutil.rrule import rrule, DAILY
from liturgical_colour.liturgical import liturgical_colour

start = date(2024,1,1)
end = date(2024,12,31)
colourfreqs = {}
for dt in rrule(DAILY, dtstart=start, until=end):
    cdt = liturgical_colour(dt)
    try:

        if cdt['colourcode'] in colourfreqs:
            colourfreqs[cdt['colourcode']] +=1
        else:
            colourfreqs[cdt['colourcode']] = 1
    except KeyError:
        print(cdt)

which gives the following output:

{'name': 'Shrove Tuesday', 'colour': 'white', 'url': 'https://en.wikipedia.org/wiki/Shrove_Tuesday', 'prec': 7, 'type': 'Festival', 'season': 'Epiphany', 'weekno': 6, 'date': datetime.date(2024, 2, 13)}
{'name': 'Ash Wednesday', 'colour': 'purple', 'url': 'https://en.wikipedia.org/wiki/Ash_Wednesday', 'prec': 9, 'type': 'Principal Feast', 'season': 'Lent', 'weekno': 0, 'date': datetime.date(2024, 2, 14)}
{'name': 'Maundy Thursday', 'colour': 'purple', 'url': 'https://en.wikipedia.org/wiki/Maundy_Thursday', 'prec': 9, 'type': 'Principal Feast', 'season': 'Lent', 'weekno': 6, 'date': datetime.date(2024, 3, 28)}
{'name': 'Good Friday', 'colour': 'purple', 'url': 'https://en.wikipedia.org/wiki/Good_Friday', 'prec': 9, 'type': 'Principal Feast', 'season': 'Lent', 'weekno': 6, 'date': datetime.date(2024, 3, 29)}
{'name': 'Pentecost', 'colour': 'red', 'url': 'https://en.wikipedia.org/wiki/Pentecost', 'prec': 9, 'type': 'Principal Feast', 'season': 'Easter', 'weekno': 7, 'date': datetime.date(2024, 5, 19)}
djjudas21 commented 8 months ago

Any thoughts on the PR, @togster?