diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/genlect-of-season-ferials-cr.py | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/scripts/genlect-of-season-ferials-cr.py b/scripts/genlect-of-season-ferials-cr.py index 13c56a3..4cca802 100644 --- a/scripts/genlect-of-season-ferials-cr.py +++ b/scripts/genlect-of-season-ferials-cr.py @@ -66,6 +66,12 @@ def slug_of(day): d = re.sub(r"\s+", " ", st(day).lower()) m = re.match(r"december (\d+)", d) # late Advent Dec 17-24: proper to the date if m and 17 <= int(m.group(1)) <= 24: return "advent-dec-" + m.group(1) + m = re.match(r"dec\.? (\d+)", d) # Christmas octave ferials Dec 29-31 + if m and 29 <= int(m.group(1)) <= 31: return "christmas-dec-" + m.group(1) + m = re.match(r"\[?\s*jan\.? (\d+)", d) # Christmas weekdays before Epiphany, Jan 2-7 + if m and 2 <= int(m.group(1)) <= 7: return "christmas-jan-" + m.group(1) + m = re.match(r"(monday|tuesday|wednesday|thursday|friday|saturday) after epiphany", d) + if m: return "christmas-after-epiphany-" + WD[m.group(1)] if "ash wednesday" in d: return "lent-after-ashes-wed" m = re.match(r"(thursday|friday|saturday) after ash", d) if m: return "lent-after-ashes-" + WD[m.group(1)] @@ -87,12 +93,18 @@ def main(): n = 0 for tr in re.split(r"<tr\b", h): c = [x for x in re.findall(r"<td\b[^>]*>(.*?)</td>", tr, re.S)] - if len(c) < 6: continue - slug = slug_of(c[2]) - if not slug: continue - cr[slug] = {"first": clean_cite(c[3]), "psalm": clean_cite(c[4]), "gospel": clean_cite(c[-1])} + if len(c) < 5: continue + # the "Day" column sits at c[2] (Advent's 7-col table) or c[1] (the + # Christmas 6-col table) — find it by which cell yields a slug, then the + # readings follow it (first, psalm, ..., gospel last). + di = next((i for i, cell in enumerate(c) if slug_of(cell)), None) + if di is None or di + 1 >= len(c): continue + slug = slug_of(c[di]) + cr[slug] = {"first": clean_cite(c[di + 1]), + "psalm": clean_cite(c[di + 2]) if di + 2 < len(c) - 1 else "", + "gospel": clean_cite(c[-1])} n += 1 - sys.stderr.write(f"{p}: {n} week-based seasonal ferials\n") + sys.stderr.write(f"{p}: {n} seasonal ferials mapped\n") text = open(INI).read() head = text[:text.index("\n[")] |
