Web Variante in Go V0.1
This commit is contained in:
1 parent
f9e3e94629
commit
692b9b6ef8
60 files changed
+13140
No files matched your search
@@ -0,0 +1,279 @@
|
||||
package liturgy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"lektorenplan/domain"
|
||||
)
|
||||
|
||||
// APIError describes a failed online calendar request.
|
||||
type APIError struct {
|
||||
Message string
|
||||
}
|
||||
|
||||
func (e *APIError) Error() string { return e.Message }
|
||||
|
||||
func apiErrorf(format string, args ...any) error {
|
||||
return &APIError{Message: fmt.Sprintf(format, args...)}
|
||||
}
|
||||
|
||||
// API talks to the eucharistiefeier.de calendar endpoint.
|
||||
type API struct {
|
||||
Diocese string
|
||||
Endpoint string
|
||||
Client *http.Client
|
||||
UserAgent string
|
||||
}
|
||||
|
||||
// NewAPI returns the default live client used by LektorenPlan.
|
||||
func NewAPI() *API {
|
||||
return &API{
|
||||
Diocese: "koeln",
|
||||
Endpoint: "https://www.eucharistiefeier.de/lk/api.php",
|
||||
Client: &http.Client{Timeout: 45 * time.Second},
|
||||
UserAgent: "LektorenPlan/1.0 (Linux; Pfarrei)",
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch downloads and parses one calendar year, filling gaps locally.
|
||||
func (a *API) Fetch(ctx context.Context, year int) ([]domain.LiturgicalDay, error) {
|
||||
endpoint, err := url.Parse(a.Endpoint)
|
||||
if err != nil {
|
||||
return nil, apiErrorf("Die Kalender-URL konnte nicht erstellt werden.")
|
||||
}
|
||||
query := endpoint.Query()
|
||||
query.Set("kal", a.Diocese)
|
||||
query.Set("jahr", strconv.Itoa(year))
|
||||
query.Set("format", "json")
|
||||
query.Set("info", "wdtrflu")
|
||||
query.Set("dup", "e")
|
||||
query.Set("bahn", "j")
|
||||
endpoint.RawQuery = query.Encode()
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
|
||||
if err != nil {
|
||||
return nil, apiErrorf("Die Kalenderanfrage konnte nicht erstellt werden (%v).", err)
|
||||
}
|
||||
userAgent := a.UserAgent
|
||||
if userAgent == "" {
|
||||
userAgent = "LektorenPlan/1.0 (Linux; Pfarrei)"
|
||||
}
|
||||
req.Header.Set("User-Agent", userAgent)
|
||||
req.Header.Set("Accept", "application/json, text/plain, */*")
|
||||
|
||||
client := a.Client
|
||||
if client == nil {
|
||||
client = &http.Client{Timeout: 45 * time.Second}
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, apiErrorf("Der liturgische Kalender war nicht erreichbar (%v).", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode < 200 || resp.StatusCode > 299 {
|
||||
return nil, apiErrorf("Der liturgische Kalender antwortete mit HTTP %d.", resp.StatusCode)
|
||||
}
|
||||
data, err := io.ReadAll(io.LimitReader(resp.Body, 16<<20))
|
||||
if err != nil {
|
||||
return nil, apiErrorf("Die Kalenderdaten konnten nicht gelesen werden (%v).", err)
|
||||
}
|
||||
return Parse(data, year)
|
||||
}
|
||||
|
||||
var leadingNumber = regexp.MustCompile(`^\d{1,2}\.\s`)
|
||||
|
||||
// Parse converts the JSON payload of the online calendar into days.
|
||||
func Parse(data []byte, year int) ([]domain.LiturgicalDay, error) {
|
||||
var root map[string]any
|
||||
if err := json.Unmarshal(data, &root); err != nil {
|
||||
return nil, apiErrorf("Die Kalenderdaten konnten nicht gelesen werden (%v).", err)
|
||||
}
|
||||
rawCelebrations, ok := root["Zelebrationen"]
|
||||
if !ok {
|
||||
return nil, apiErrorf("Die Kalenderdaten konnten nicht gelesen werden (Zelebrationen fehlen).")
|
||||
}
|
||||
|
||||
entries := decodeEntries(rawCelebrations)
|
||||
grouped := map[string][]map[string]any{}
|
||||
for _, entry := range entries {
|
||||
date, _ := entry["Datum"].(string)
|
||||
grouped[date] = append(grouped[date], entry)
|
||||
}
|
||||
|
||||
keys := make([]string, 0, len(grouped))
|
||||
for key := range grouped {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
prefix := strconv.Itoa(year)
|
||||
var days []domain.LiturgicalDay
|
||||
for _, dateKey := range keys {
|
||||
if !strings.HasPrefix(dateKey, prefix) {
|
||||
continue
|
||||
}
|
||||
date, ok := domain.DateFromKey(dateKey)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
var valid []map[string]any
|
||||
for _, entry := range grouped[dateKey] {
|
||||
title := stringField(entry, "Tl")
|
||||
remark := stringField(entry, "Bem")
|
||||
if strings.Contains(title, "Bahnlesungen") {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(title, "Kommemoration") {
|
||||
continue
|
||||
}
|
||||
if title == "Weihe der eigenen Kirche" && strings.HasPrefix(remark, "Wenn") {
|
||||
continue
|
||||
}
|
||||
valid = append(valid, entry)
|
||||
}
|
||||
if len(valid) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
best := valid[0]
|
||||
bestScore := scoreEntry(best, date)
|
||||
for _, entry := range valid[1:] {
|
||||
if s := scoreEntry(entry, date); s > bestScore {
|
||||
best, bestScore = entry, s
|
||||
}
|
||||
}
|
||||
|
||||
readingEntry := best
|
||||
if stringField(best, "L1") == "" && stringField(best, "EV") == "" {
|
||||
bestLen := readingLength(readingEntry)
|
||||
for _, entry := range valid {
|
||||
if l := readingLength(entry); l > bestLen {
|
||||
readingEntry, bestLen = entry, l
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
title := stringField(best, "Tl")
|
||||
colorValue := stringField(best, "Farbe")
|
||||
if colorValue == "" {
|
||||
colorValue = stringField(readingEntry, "Farbe")
|
||||
}
|
||||
days = append(days, domain.LiturgicalDay{
|
||||
Date: date,
|
||||
Title: title,
|
||||
Rank: domain.LiturgicalRank(stringField(best, "Rang")),
|
||||
Color: domain.LiturgicalColorFromAPI(colorValue),
|
||||
Remark: stringField(best, "Bem"),
|
||||
Readings: domain.Readings{
|
||||
First: stringField(readingEntry, "L1"),
|
||||
Psalm: stringField(readingEntry, "AP"),
|
||||
Second: stringField(readingEntry, "L2"),
|
||||
Gospel: stringField(readingEntry, "EV"),
|
||||
},
|
||||
IsObligation: IsObligation(date, title),
|
||||
Source: SourceLabel,
|
||||
UpdatedAt: domain.Normalize(time.Now()),
|
||||
})
|
||||
}
|
||||
|
||||
if len(days) == 0 {
|
||||
return nil, apiErrorf("Für %d wurden keine liturgischen Daten geliefert.", year)
|
||||
}
|
||||
return FillLocalGaps(year, days), nil
|
||||
}
|
||||
|
||||
func decodeEntries(raw any) []map[string]any {
|
||||
var entries []map[string]any
|
||||
switch value := raw.(type) {
|
||||
case []any:
|
||||
for _, item := range value {
|
||||
if entry, ok := item.(map[string]any); ok {
|
||||
entries = append(entries, entry)
|
||||
}
|
||||
}
|
||||
case map[string]any:
|
||||
for _, item := range value {
|
||||
if entry, ok := item.(map[string]any); ok {
|
||||
entries = append(entries, entry)
|
||||
}
|
||||
}
|
||||
}
|
||||
return entries
|
||||
}
|
||||
|
||||
func stringField(entry map[string]any, key string) string {
|
||||
if value, ok := entry[key].(string); ok {
|
||||
return value
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func readingLength(entry map[string]any) int {
|
||||
total := 0
|
||||
for _, key := range []string{"L1", "AP", "L2", "EV"} {
|
||||
total += utf8.RuneCountInString(stringField(entry, key))
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
func scoreEntry(entry map[string]any, date time.Time) int {
|
||||
value := 0
|
||||
switch stringField(entry, "Rang") {
|
||||
case "H":
|
||||
value += 120
|
||||
case "F":
|
||||
value += 110
|
||||
case "G":
|
||||
value += 80
|
||||
case "g":
|
||||
value += 60
|
||||
default:
|
||||
value += 50
|
||||
}
|
||||
title := stringField(entry, "Tl")
|
||||
remark := stringField(entry, "Bem")
|
||||
lowerTitle := strings.ToLower(title)
|
||||
|
||||
if domain.IsSunday(date) {
|
||||
if strings.Contains(lowerTitle, "sonntag") || strings.Contains(lowerTitle, "taufe des herrn") {
|
||||
value += 100
|
||||
}
|
||||
if stringField(entry, "Rang") == "" {
|
||||
value += 30
|
||||
}
|
||||
}
|
||||
switch {
|
||||
case strings.Contains(remark, "Am Tag"):
|
||||
value += 18
|
||||
case strings.Contains(remark, "Am Morgen"):
|
||||
value += 12
|
||||
case strings.Contains(remark, "Am Vorabend"):
|
||||
value -= 4
|
||||
case strings.Contains(remark, "In der Heiligen Nacht"):
|
||||
value += 5
|
||||
}
|
||||
if strings.Contains(remark, "Hochfest") {
|
||||
value += 10
|
||||
}
|
||||
if leadingNumber.MatchString(title) {
|
||||
value -= 25
|
||||
}
|
||||
if stringField(entry, "L1") != "" || stringField(entry, "EV") != "" {
|
||||
value += 20
|
||||
}
|
||||
if strings.Contains(lowerTitle, "im jahreskreis") || strings.Contains(lowerTitle, "osterzeit") {
|
||||
value += 5
|
||||
}
|
||||
return value
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"version":1,"source":"www.eucharistiefeier.de","diocese":"Erzbistum Köln","years":[2025,2026,2027,2028],"days":[{"date":"2025-01-01","title":"1. Januar - Neujahr","rank":"H","color":"w","bem":"Hochfest der Gottesmutter Maria","l1":"Num 6, 22-27","ap":"Ps 67 (66), 2-3.5.6 u. 8 (R: 2a)","l2":"Gal 4, 4-7","ev":"Lk 2, 16-21","obligation":true},{"date":"2025-01-02","title":"Hl. Basilius der Große (379) und hl. Gregor von Nazianz (um 390), Bischöfe, Kirchenlehrer","rank":"G","color":"w","bem":"","l1":"Eph 4, 1-7.11-13","ap":"Ps 23 (22), 1-3.4.5.6 (R: 1)","l2":"","ev":"Mt 23, 8-12","obligation":false},{"date":"2025-01-03","title":"Heiligster Name Jesu","rank":"g","color":"w","bem":"","l1":"Phil 2, 1-11","ap":"Ps 8, 4-5.6-7.8-9 (R: 2a)","l2":"","ev":"Lk 2, 21-24","obligation":false},{"date":"2025-01-04","title":"4. Januar","rank":"","color":"w","bem":"","l1":"1 Joh 3, 7-10","ap":"Ps 98 (97), 1.7-8.9 (R: vgl. 3cd)","l2":"","ev":"Joh 1, 35-42","obligation":false},{"date":"2025-01-05","title":"2. Sonntag nach Weihnachten","rank":"","color":"w","bem":"","l1":"Sir 24, 1-2.8-12 (1-4.12-16)","ap":"Ps 147, 12-13.14-15.19-20 (R: Joh 1, 14)","l2":"Eph 1, 3-6.15-18","ev":"Joh 1, 1-18","obligation":true},{"date":"2025-01-06","title":"Erscheinung des Herrn","rank":"H","color":"w","bem":"","l1":"Jes 60, 1-6","ap":"Ps 72 (71), 1-2.7-8.10-11.12-13 (R: 11)","l2":"Eph 3, 2-3a.5-6","ev":"Mt 2, 1-12","obligation":true},{"date":"2025-01-07","title":"Hl. Raimund von Peñafort, Ordensgründer (1275)","rank":"g","color":"w","bem":"","l1":"2 Kor 5, 14-20","ap":"Ps 103 (102), 1-2.3-4.8-9.13-14.17-18a (R: 11)","l2":"","ev":"Lk 12, 35-40","obligation":false},{"date":"2025-01-08","title":"Hl. Severin, Mönch in Norikum (482)","rank":"g","color":"w","bem":"","l1":"Jak 2, 14-17","ap":"Ps 107 (106), 1-2a u. 3.4-5.6-7.8-9 (R: vgl. Spr 31, 20)","l2":"","ev":"Mt 25, 31-46","obligation":false},{"date":"2025-01-09","title":"9. Januar","rank":"","color":"w","bem":"","l1":"1 Joh 4, 11-18","ap":"Ps 72 (71), 1-2.10-11.12-13 (R: 11)","l2":"","ev":"Mk 6, 45-52","obligation":false},{"date":"2025-01-10","title":"10. Januar","rank":"","color":"w","bem":"","l1":"1 Joh 4, 19 - 5, 4","ap":"Ps 72 (71), 1-2.14 u. 15bc.17 (R: 11)","l2":"","ev":"Lk 4, 14-22a","obligation":false},{"date":"2025-01-11","title":"11. Januar","rank":"","color":"w","bem":"","l1":"1 Joh 5, 5-13","ap":"Ps 147, 12-13.14-15.19-20 (R: 12a)","l2":"","ev":"Lk 5, 12-16","obligation":false},{"date":"2025-01-12","title":"Taufe des Herrn","rank":"F","color":"w","bem":"Sonntag nach dem 6. Januar","l1":"Jes 42, 5a.1-4.6-7 oder Jes 40, 1-5.9-11","ap":"Ps 29 (28), 1-2.3ac-4.3b u. 9b-10 (R: vgl. 11b) oder Ps 104 (103), 1-2.3-4.24-25.27-28.29-30 (R: 1ab)","l2":"Apg 10, 34-38 oder Tit 2, 11-14; 3, 4-7","ev":"Lk 3, 15-16.21-22","obligation":true},{"date":"2025-01-13","title":"Hl. Hilarius, Bischof von Poitiers, Kirchenlehrer (um 367)","rank":"g","color":"w","bem":"","l1":"1 Joh 2, 18-25","ap":"Ps 110 (109), 1-2.3.4-5 (R: 4b)","l2":"","ev":"Mt 5, 13-19","obligation":false},{"date":"2025-01-14","title":"Dienstag der 1. Woche im Jahreskreis","rank":"","color":"g","bem":"","l1":"Hebr 2, 5-12","ap":"Ps 8, 2 u. 5.6-7.8-9 (R: vgl. 7)","l2":"","ev":"Mk 1, 21-28","obligation":false},{"date":"2025-01-15","title":"Mittwoch der 1. Woche im Jahreskreis","rank":"","color":"g","bem":"","l1":"Hebr 2, 11-12.13c-18","ap":"Ps 105 (104), 1-2.3-4.6-7.8-9 (R: 7a.8a)","l2":"","ev":"Mk 1, 29-39","obligation":false},{"date":"2025-01-16","title":"Donnerstag der 1. Woche im Jahreskreis","rank":"","color":"g","bem":"","l1":"Hebr 3, 7-14","ap":"Ps 95 (94), 6-7b.7c-9.10-11 (R: vgl. 7c.8a)","l2":"","ev":"Mk 1, 40-45","obligation":false},{"date":"2025-01-17","title":"Hl. Antonius, Mönchsvater in Ägypten (356)","rank":"G","color":"w","bem":"","l1":"Eph 6, 10-13.18","ap":"Ps 16 (15), 1-2 u. 5.7-8.9 u. 11 (R: vgl. 5a)","l2":"","ev":"Mt 19, 16-26","obligation":false},{"date":"2025-01-18","title":"Samstag der 1. Woche im Jahreskreis","rank":"","color":"g","bem":"","l1":"Hebr 4, 12-16","ap":"Ps 19 (18B), 8.9.10.11 u. 15 (R: vgl. Joh 6, 63b)","l2":"","ev":"Mk 2, 13-17","obligation":false},{"date":"2025-01-19","title":"2. Sonntag im Jahreskreis","rank":"","color":"g","bem":"","l1":"Jes 62, 1-5","ap":"Ps 96 (95), 1-2.3-4.6-7.10 (R: vgl. 3a)","l2":"1 Kor 12, 4-11","ev":"Joh 2, 1-11","obligation":true},{"date":"2025-01-20","title":"Hl. Fabian, Papst, Märtyrer (250)","rank":"g","color":"r","bem":"","l1":"1 Petr 5, 1-4","ap":"Ps 40 (39), 2 u. 4ab.7-8.9-10 (R: vgl. 8a.9a)","l2":"","ev":"Joh 21, 1.15-17","obligation":false},{"date":"2025-01-21","title":"Hl. Agnes, Jungfrau, Märtyrin in Rom (304)","rank":"g","color":"r","bem":"","l1":"1 Kor 1, 26-31","ap":"Ps 23 (22), 1-3.4.5.6 (R: 1)","l2":"","ev":"Mt 13, 44-46","obligation":false},{"date":"2025-01-22","title":"Hl. Vinzenz, Diakon, Märtyrer in Spanien (304)","rank":"g","color":"r","bem":"","l1":"2 Kor 4, 7-15","ap":"Ps 34 (33), 2-3.4-5.6-7.8-9 (R: vgl. 5b)","l2":"","ev":"Mt 10, 17-22","obligatioLine truncated
|
||||
@@ -0,0 +1,287 @@
|
||||
// Package liturgy implements the local liturgical calendar and the optional
|
||||
// online source www.eucharistiefeier.de used by LektorenPlan.
|
||||
package liturgy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"lektorenplan/domain"
|
||||
)
|
||||
|
||||
// Moveable feasts -----------------------------------------------------------
|
||||
|
||||
func EasterSunday(year int) time.Time { return domain.EasterSunday(year) }
|
||||
func AshWednesday(y int) time.Time { return domain.AshWednesday(y) }
|
||||
func PalmSunday(y int) time.Time { return domain.PalmSunday(y) }
|
||||
func HolyThursday(y int) time.Time { return domain.HolyThursday(y) }
|
||||
func GoodFriday(y int) time.Time { return domain.GoodFriday(y) }
|
||||
func HolySaturday(y int) time.Time { return domain.HolySaturday(y) }
|
||||
func Ascension(y int) time.Time { return domain.Ascension(y) }
|
||||
func Pentecost(y int) time.Time { return domain.Pentecost(y) }
|
||||
func CorpusChristi(y int) time.Time { return domain.CorpusChristi(y) }
|
||||
func SacredHeart(y int) time.Time { return domain.SacredHeart(y) }
|
||||
func TrinitySunday(y int) time.Time { return domain.TrinitySunday(y) }
|
||||
func AdventStart(year int) time.Time { return domain.AdventStart(year) }
|
||||
func ChristKing(year int) time.Time { return domain.ChristKing(year) }
|
||||
func BaptismOfTheLord(year int) time.Time { return domain.BaptismOfTheLord(year) }
|
||||
|
||||
// Seasons -------------------------------------------------------------------
|
||||
|
||||
func SeasonFor(date time.Time) domain.LiturgicalSeason { return domain.SeasonFor(date) }
|
||||
func SeasonName(date time.Time) string { return SeasonFor(date).Title() }
|
||||
|
||||
// Obligation ----------------------------------------------------------------
|
||||
|
||||
func IsObligation(date time.Time, title string) bool {
|
||||
if domain.IsSunday(date) {
|
||||
return true
|
||||
}
|
||||
m, d := domain.Month(date), domain.DayNumber(date)
|
||||
switch {
|
||||
case m == 1 && d == 1, m == 1 && d == 6, m == 8 && d == 15, m == 11 && d == 1, m == 12 && d == 25:
|
||||
return true
|
||||
}
|
||||
lower := strings.ToLower(title)
|
||||
if strings.Contains(lower, "fronleichnam") ||
|
||||
strings.Contains(lower, "christi himmelfahrt") ||
|
||||
(strings.Contains(lower, "pfingsten") && !strings.Contains(lower, "vorabend")) ||
|
||||
strings.Contains(lower, "ostersonntag") || strings.Contains(lower, "osternacht") {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Symbols -------------------------------------------------------------------
|
||||
|
||||
func SymbolFor(title string, rank domain.LiturgicalRank, date time.Time) domain.FeastSymbol {
|
||||
return domain.SymbolFor(title, rank, date)
|
||||
}
|
||||
|
||||
// Local fallback ------------------------------------------------------------
|
||||
|
||||
var fixedReadings = map[string]domain.Readings{
|
||||
"01-01": {First: "Num 6, 22-27", Psalm: "Ps 67 (66), 2-3.5.6 u. 8 (R: 2a)", Second: "Gal 4, 4-7", Gospel: "Lk 2, 16-21"},
|
||||
"01-06": {First: "Jes 60, 1-6", Psalm: "Ps 72 (71), 1-2.7-8.10-11.12-13 (R: 11)", Second: "Eph 3, 2-3a.5-6", Gospel: "Mt 2, 1-12"},
|
||||
"02-02": {First: "Mal 3, 1-4", Psalm: "Ps 24 (23), 7-8.9-10 (R: 8a)", Second: "Hebr 2, 14-18", Gospel: "Lk 2, 22-40"},
|
||||
"03-19": {First: "2 Sam 7, 4-5a.12-14a.16", Psalm: "Ps 89 (88), 2-3.4-5.27.29 (R: 37)", Second: "Röm 4, 13.16-18.22", Gospel: "Mt 1, 16.18-21.24a"},
|
||||
"03-25": {First: "Jes 7, 10-14", Psalm: "Ps 40 (39), 5-6.7-8a.8b-10 (R: 8a.9a)", Second: "Hebr 10, 4-10", Gospel: "Lk 1, 26-38"},
|
||||
"06-24": {First: "Jes 49, 1-6", Psalm: "Ps 139 (138), 1-3.13-14ab.14c-15 (R: 14a)", Second: "Apg 13, 22-26", Gospel: "Lk 1, 57-66.80"},
|
||||
"06-29": {First: "Apg 12, 1-11", Psalm: "Ps 34 (33), 2-3.4-5.6-7.8-9 (R: 5b)", Second: "2 Tim 4, 6-8.17-18", Gospel: "Mt 16, 13-19"},
|
||||
"08-15": {First: "Offb 11, 19a; 12, 1-6a.10ab", Psalm: "Ps 45 (44), 11-12.16-17 (R: 10b)", Second: "1 Kor 15, 20-27", Gospel: "Lk 1, 39-56"},
|
||||
"09-14": {First: "Num 21, 4b-9", Psalm: "Ps 78 (77), 1-2.34-35.36-37.38 (R: 7b)", Second: "Phil 2, 6-11", Gospel: "Joh 3, 13-17"},
|
||||
"11-01": {First: "Offb 7, 2-4.9-14", Psalm: "Ps 24 (23), 1-2.3-4.5-6 (R: vgl. 6)", Second: "1 Joh 3, 1-3", Gospel: "Mt 5, 1-12a"},
|
||||
"11-02": {First: "Jes 25, 6a.7-9", Psalm: "Ps 23 (22), 1-3a.3b-4.5.6 (R: 1)", Second: "Röm 8, 14-23", Gospel: "Mt 25, 31-46"},
|
||||
"12-08": {First: "Gen 3, 9-15.20", Psalm: "Ps 98 (97), 1.2-3ab.3cd-4 (R: 1a)", Second: "Eph 1, 3-6.11-12", Gospel: "Lk 1, 26-38"},
|
||||
"12-24": {First: "2 Sam 7, 1-5.8b-12.14a.16", Psalm: "Ps 89 (88), 2-3.20a u. 4-5.27 u. 29 (R: 2a)", Gospel: "Lk 1, 67-79"},
|
||||
"12-25": {First: "Jes 52, 7-10", Psalm: "Ps 98 (97), 1.2-3b.3c-4.5-6 (R: vgl. 3cd)", Second: "Hebr 1, 1-6", Gospel: "Joh 1, 1-18"},
|
||||
"12-26": {First: "Apg 6, 8-10; 7, 54-59", Psalm: "Ps 31 (30), 3-4.6.8.17 (R: 6a)", Gospel: "Mt 10, 17-22"},
|
||||
}
|
||||
|
||||
var easterReadings = map[int]domain.Readings{
|
||||
-46: {First: "Joel 2, 12-18", Psalm: "Ps 51 (50), 3-4.5-6a.12-13.14 u. 17 (R: vgl. 3a)", Second: "2 Kor 5, 20 - 6, 2", Gospel: "Mt 6, 1-6.16-18"},
|
||||
-7: {First: "Jes 50, 4-7", Psalm: "Ps 22 (21), 8-9.17-18a.19-20.23-24 (R: 2a)", Second: "Phil 2, 6-11", Gospel: "Mt 21, 1-11"},
|
||||
-3: {First: "Ex 12, 1-8.11-14", Psalm: "Ps 116 (115), 12-13.15-16bc.17-18 (R: vgl. 1 Kor 10, 16)", Second: "1 Kor 11, 23-26", Gospel: "Joh 13, 1-15"},
|
||||
-2: {First: "Jes 52, 13 - 53, 12", Psalm: "Ps 31 (30), 2 u. 6.12-13.15-16.17 u. 25 (R: Lk 23, 46)", Second: "Hebr 4, 14-16; 5, 7-9", Gospel: "Joh 18, 1 - 19, 42"},
|
||||
0: {First: "Apg 10, 34a.37-43", Psalm: "Ps 118 (117), 1-2.16-17.22-23 (R: vgl. 24)", Second: "Kol 3, 1-4 oder 1 Kor 5, 6b-8", Gospel: "Joh 20, 1-9"},
|
||||
39: {First: "Apg 1, 1-11", Psalm: "Ps 47 (46), 2-3.6-7.8-9 (R: 6)", Second: "Eph 1, 17-23", Gospel: "Mk 16, 15-20"},
|
||||
49: {First: "Apg 2, 1-11", Psalm: "Ps 104 (103), 1-2.24-25.29-30.31 u. 34 (R: vgl. 30)", Second: "1 Kor 12, 3b-7.12-13", Gospel: "Joh 20, 19-23"},
|
||||
56: {First: "Spr 8, 22-31", Psalm: "Ps 8, 4-5.6-7.8-9 (R: 2a)", Second: "Röm 5, 1-5", Gospel: "Joh 16, 12-15"},
|
||||
60: {First: "Dtn 8, 2-3.14-16a", Psalm: "Ps 147, 12-13.14-15.19-20 (R: 12a)", Second: "1 Kor 10, 16-17", Gospel: "Joh 6, 51-58"},
|
||||
68: {First: "Hos 11, 1.3-4.8c-9", Psalm: "Jes 12, 2-3.4bcd.5-6 (R: 3)", Second: "Eph 3, 8-12.14-19", Gospel: "Joh 19, 31-37"},
|
||||
}
|
||||
|
||||
// LocalDay builds the offline fallback for one date.
|
||||
func LocalDay(date time.Time) domain.LiturgicalDay {
|
||||
day := domain.Normalize(date)
|
||||
y := domain.Year(day)
|
||||
m := domain.Month(day)
|
||||
d := domain.DayNumber(day)
|
||||
key := fmt.Sprintf("%02d-%02d", m, d)
|
||||
weekday := domain.Weekday(day)
|
||||
easter := EasterSunday(y)
|
||||
offset := domain.DaysBetween(easter, day)
|
||||
|
||||
title := ""
|
||||
rank := domain.RankWeekday
|
||||
color := domain.ColorGreen
|
||||
readings := domain.Readings{}
|
||||
remark := ""
|
||||
|
||||
switch offset {
|
||||
case -46:
|
||||
title, rank, color, readings = "Aschermittwoch", domain.RankWeekday, domain.ColorViolet, easterReadings[-46]
|
||||
case -7:
|
||||
title, rank, color, readings = "Palmsonntag", domain.RankFeast, domain.ColorRed, easterReadings[-7]
|
||||
case -3:
|
||||
title, rank, color, readings = "Gründonnerstag", domain.RankSolemnity, domain.ColorWhite, easterReadings[-3]
|
||||
case -2:
|
||||
title, rank, color, readings = "Karfreitag", domain.RankSolemnity, domain.ColorRed, easterReadings[-2]
|
||||
case -1:
|
||||
title, rank, color = "Karsamstag", domain.RankWeekday, domain.ColorViolet
|
||||
case 0:
|
||||
title, rank, color, readings = "Ostersonntag", domain.RankSolemnity, domain.ColorWhite, easterReadings[0]
|
||||
remark = "Hochfest der Auferstehung des Herrn"
|
||||
case 1:
|
||||
title, rank, color = "Ostermontag", domain.RankSolemnity, domain.ColorWhite
|
||||
readings = domain.Readings{First: "Apg 2, 14.22-33", Psalm: "Ps 16 (15), 1-2a u. 5.7-8.9-10.11 (R: 11a)", Gospel: "Mt 28, 8-15"}
|
||||
case 39:
|
||||
title, rank, color, readings = "Christi Himmelfahrt", domain.RankSolemnity, domain.ColorWhite, easterReadings[39]
|
||||
case 49:
|
||||
title, rank, color, readings = "Pfingsten", domain.RankSolemnity, domain.ColorRed, easterReadings[49]
|
||||
remark = "Hochfest des Heiligen Geistes"
|
||||
case 50:
|
||||
title, rank, color = "Pfingstmontag", domain.RankSolemnity, domain.ColorRed
|
||||
readings = domain.Readings{First: "Apg 10, 34a.37-43", Psalm: "Ps 118 (117), 1-2.16-17.22-23 (R: vgl. 24)", Second: "Kol 3, 1-4", Gospel: "Joh 20, 1-9"}
|
||||
case 56:
|
||||
title, rank, color, readings = "Dreifaltigkeitssonntag", domain.RankSolemnity, domain.ColorWhite, easterReadings[56]
|
||||
case 60:
|
||||
title, rank, color, readings = "Fronleichnam", domain.RankSolemnity, domain.ColorWhite, easterReadings[60]
|
||||
remark = "Hochfest des Leibes und Blutes Christi"
|
||||
case 68:
|
||||
title, rank, color, readings = "Heiligstes Herz Jesu", domain.RankSolemnity, domain.ColorWhite, easterReadings[68]
|
||||
}
|
||||
|
||||
if title == "" {
|
||||
switch key {
|
||||
case "01-01":
|
||||
title, rank, color = "Neujahr – Hochfest der Gottesmutter Maria", domain.RankSolemnity, domain.ColorWhite
|
||||
case "01-06":
|
||||
title, rank, color = "Erscheinung des Herrn", domain.RankSolemnity, domain.ColorWhite
|
||||
case "02-02":
|
||||
title, rank, color = "Darstellung des Herrn", domain.RankFeast, domain.ColorWhite
|
||||
case "03-19":
|
||||
title, rank, color = "Hl. Josef, Bräutigam der Gottesmutter", domain.RankSolemnity, domain.ColorWhite
|
||||
case "03-25":
|
||||
title, rank, color = "Verkündigung des Herrn", domain.RankSolemnity, domain.ColorWhite
|
||||
case "06-24":
|
||||
title, rank, color = "Geburt Johannes' des Täufers", domain.RankSolemnity, domain.ColorWhite
|
||||
case "06-29":
|
||||
title, rank, color = "Petrus und Paulus", domain.RankSolemnity, domain.ColorRed
|
||||
case "08-15":
|
||||
title, rank, color = "Mariä Aufnahme in den Himmel", domain.RankSolemnity, domain.ColorWhite
|
||||
case "09-14":
|
||||
title, rank, color = "Kreuzerhöhung", domain.RankFeast, domain.ColorRed
|
||||
case "11-01":
|
||||
title, rank, color = "Allerheiligen", domain.RankSolemnity, domain.ColorWhite
|
||||
case "11-02":
|
||||
title, rank, color = "Allerseelen", domain.RankWeekday, domain.ColorViolet
|
||||
case "12-08":
|
||||
title, rank, color = "Mariä Empfängnis", domain.RankSolemnity, domain.ColorWhite
|
||||
case "12-24":
|
||||
title, rank, color = "Heiliger Abend", domain.RankWeekday, domain.ColorWhite
|
||||
case "12-25":
|
||||
title, rank, color = "Weihnachten – Hochfest der Geburt des Herrn", domain.RankSolemnity, domain.ColorWhite
|
||||
case "12-26":
|
||||
title, rank, color = "Hl. Stephanus", domain.RankFeast, domain.ColorRed
|
||||
}
|
||||
if r, ok := fixedReadings[key]; ok {
|
||||
readings = r
|
||||
}
|
||||
}
|
||||
|
||||
if title == "" {
|
||||
if weekday == 1 {
|
||||
title = sundayTitle(day)
|
||||
color = domain.ColorGreen
|
||||
if seasonal := seasonalSundayRank(day); seasonal != domain.RankWeekday {
|
||||
rank = seasonal
|
||||
}
|
||||
} else {
|
||||
title = weekdayTitle(day)
|
||||
season := SeasonFor(day)
|
||||
if season == domain.SeasonAdvent || season == domain.SeasonLent {
|
||||
color = domain.ColorViolet
|
||||
} else if season == domain.SeasonChristmas || season == domain.SeasonEaster {
|
||||
color = domain.ColorWhite
|
||||
} else {
|
||||
color = domain.ColorGreen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if rank == domain.RankSolemnity {
|
||||
color = domain.ColorWhite
|
||||
}
|
||||
if rank == domain.RankFeast && color == domain.ColorGreen {
|
||||
color = domain.ColorRed
|
||||
}
|
||||
|
||||
return domain.LiturgicalDay{
|
||||
Date: day, Title: title, Rank: rank, Color: color, Remark: remark,
|
||||
Readings: readings, IsObligation: IsObligation(day, title),
|
||||
Source: "lokale Berechnung", UpdatedAt: domain.Normalize(time.Now()),
|
||||
}
|
||||
}
|
||||
|
||||
func LocalDays(r domain.DayRange) []domain.LiturgicalDay {
|
||||
days := r.Days()
|
||||
out := make([]domain.LiturgicalDay, 0, len(days))
|
||||
for _, day := range days {
|
||||
out = append(out, LocalDay(day))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func seasonalSundayRank(day time.Time) domain.LiturgicalRank {
|
||||
season := SeasonFor(day)
|
||||
if season == domain.SeasonAdvent || season == domain.SeasonChristmas || season == domain.SeasonLent || season == domain.SeasonEaster {
|
||||
if season == domain.SeasonLent && domain.DaysBetween(PalmSunday(domain.Year(day)), day) == 0 {
|
||||
return domain.RankFeast
|
||||
}
|
||||
return domain.RankWeekday
|
||||
}
|
||||
return domain.RankWeekday
|
||||
}
|
||||
|
||||
func sundayTitle(day time.Time) string {
|
||||
y := domain.Year(day)
|
||||
switch SeasonFor(day) {
|
||||
case domain.SeasonAdvent:
|
||||
index := domain.DaysBetween(AdventStart(y), day)/7 + 1
|
||||
names := []string{"1. Adventssonntag", "2. Adventssonntag", "3. Adventssonntag", "4. Adventssonntag"}
|
||||
if index >= 1 && index <= len(names) {
|
||||
return names[index-1]
|
||||
}
|
||||
return "Adventssonntag"
|
||||
case domain.SeasonChristmas:
|
||||
if domain.DaysBetween(BaptismOfTheLord(y), day) == 0 {
|
||||
return "Taufe des Herrn"
|
||||
}
|
||||
return "Sonntag in der Weihnachtszeit"
|
||||
case domain.SeasonLent:
|
||||
index := domain.DaysBetween(AshWednesday(y), day)/7 + 1
|
||||
if index >= 6 {
|
||||
return "Palmsonntag"
|
||||
}
|
||||
return fmt.Sprintf("%d. Fastensonntag", index)
|
||||
case domain.SeasonEaster:
|
||||
index := domain.DaysBetween(EasterSunday(y), day)/7 + 1
|
||||
if index == 1 {
|
||||
return "Ostersonntag"
|
||||
}
|
||||
if index == 8 {
|
||||
return "Pfingsten"
|
||||
}
|
||||
return fmt.Sprintf("%d. Sonntag der Osterzeit", index)
|
||||
default:
|
||||
return "Sonntag im Jahreskreis"
|
||||
}
|
||||
}
|
||||
|
||||
func weekdayTitle(day time.Time) string {
|
||||
name := domain.WeekdayName(day)
|
||||
switch SeasonFor(day) {
|
||||
case domain.SeasonAdvent:
|
||||
return name + " im Advent"
|
||||
case domain.SeasonChristmas:
|
||||
return name + " in der Weihnachtszeit"
|
||||
case domain.SeasonLent:
|
||||
return name + " in der Fastenzeit"
|
||||
case domain.SeasonEaster:
|
||||
return name + " in der Osterzeit"
|
||||
default:
|
||||
return name + " im Jahreskreis"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package liturgy
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"lektorenplan/domain"
|
||||
)
|
||||
|
||||
// SourceLabel is the attribution required by the data source.
|
||||
const SourceLabel = "Daten von www.eucharistiefeier.de"
|
||||
|
||||
//go:embed liturgical-snapshot.json
|
||||
var snapshotJSON []byte
|
||||
|
||||
type snapshotFile struct {
|
||||
Version int `json:"version"`
|
||||
Source string `json:"source"`
|
||||
Diocese string `json:"diocese"`
|
||||
Years []int `json:"years"`
|
||||
Days []snapshotDay `json:"days"`
|
||||
}
|
||||
|
||||
type snapshotDay struct {
|
||||
Date string `json:"date"`
|
||||
Title string `json:"title"`
|
||||
Rank string `json:"rank"`
|
||||
Color string `json:"color"`
|
||||
Remark string `json:"bem"`
|
||||
First string `json:"l1"`
|
||||
Psalm string `json:"ap"`
|
||||
Second string `json:"l2"`
|
||||
Gospel string `json:"ev"`
|
||||
Obligation bool `json:"obligation"`
|
||||
}
|
||||
|
||||
var (
|
||||
cachedSnapshot []domain.LiturgicalDay
|
||||
cachedSnapshotOnce bool
|
||||
)
|
||||
|
||||
func loadSnapshot() (snapshotFile, error) {
|
||||
var file snapshotFile
|
||||
if err := json.Unmarshal(snapshotJSON, &file); err != nil {
|
||||
return file, fmt.Errorf("liturgical snapshot: %w", err)
|
||||
}
|
||||
return file, nil
|
||||
}
|
||||
|
||||
// SnapshotLoaded reports whether the embedded JSON could be decoded.
|
||||
func SnapshotLoaded() bool {
|
||||
_, err := loadSnapshot()
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// SnapshotYears returns the years covered by the embedded snapshot.
|
||||
func SnapshotYears() []int {
|
||||
file, err := loadSnapshot()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return file.Years
|
||||
}
|
||||
|
||||
// SnapshotDays returns the bundled offline calendar.
|
||||
func SnapshotDays() []domain.LiturgicalDay {
|
||||
if cachedSnapshotOnce {
|
||||
return cachedSnapshot
|
||||
}
|
||||
cachedSnapshotOnce = true
|
||||
file, err := loadSnapshot()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
days := make([]domain.LiturgicalDay, 0, len(file.Days))
|
||||
for _, entry := range file.Days {
|
||||
date, ok := domain.DateFromKey(entry.Date)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
days = append(days, domain.LiturgicalDay{
|
||||
Date: date,
|
||||
Title: entry.Title,
|
||||
Rank: domain.LiturgicalRank(entry.Rank),
|
||||
Color: domain.LiturgicalColorFromAPI(entry.Color),
|
||||
Remark: entry.Remark,
|
||||
Readings: domain.Readings{
|
||||
First: entry.First,
|
||||
Psalm: entry.Psalm,
|
||||
Second: entry.Second,
|
||||
Gospel: entry.Gospel,
|
||||
},
|
||||
IsObligation: entry.Obligation,
|
||||
Source: SourceLabel,
|
||||
UpdatedAt: domain.Normalize(time.Now()),
|
||||
})
|
||||
}
|
||||
cachedSnapshot = days
|
||||
return days
|
||||
}
|
||||
|
||||
// SnapshotDaysForYear returns the bundled days of one calendar year.
|
||||
func SnapshotDaysForYear(year int) []domain.LiturgicalDay {
|
||||
var out []domain.LiturgicalDay
|
||||
for _, day := range SnapshotDays() {
|
||||
if domain.Year(day.Date) == year {
|
||||
out = append(out, day)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// SnapshotMissing returns bundled days whose date keys are not yet present.
|
||||
func SnapshotMissing(existing map[string]bool) []domain.LiturgicalDay {
|
||||
var out []domain.LiturgicalDay
|
||||
for _, day := range SnapshotDays() {
|
||||
if !existing[day.DateKey()] {
|
||||
out = append(out, day)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// FillLocalGaps completes a year with the local calendar so a plan never has
|
||||
// empty rows when the online source omits days.
|
||||
func FillLocalGaps(year int, days []domain.LiturgicalDay) []domain.LiturgicalDay {
|
||||
seen := make(map[string]bool, len(days))
|
||||
for _, day := range days {
|
||||
seen[day.DateKey()] = true
|
||||
}
|
||||
for _, day := range domain.YearRange(year).Days() {
|
||||
if !seen[domain.Key(day)] {
|
||||
days = append(days, LocalDay(day))
|
||||
}
|
||||
}
|
||||
sortDays(days)
|
||||
return days
|
||||
}
|
||||
|
||||
func sortDays(days []domain.LiturgicalDay) {
|
||||
sort.Slice(days, func(i, j int) bool { return days[i].Date.Before(days[j].Date) })
|
||||
}
|
||||
Reference in new issue
Block a user