- neue Datei jottalinks.txt: Format NNN<TAB>URL, #-Kommentare, nur http(s) - katalog_web.py: parse_jottalinks(), neue Spalte 'Download' mit ⬇-MP3-Button in sendungen.html, Zaehler 'mit Download-Link' auf index.html, Footer-Hinweis - neue_sendungen.py: Hinweis auf jottalinks.txt nach dem Lauf - README: Anleitung manuelles Eintragen + Warnung (oeffentliche Links ohne Passwortschutz bei Jottacloud -> Seite ggf. per .htaccess schuetzen) - web/ neu generiert (720 Sendungen, Spalte Download, noch 0 Links) - Skripte + jottalinks.txt als Kopien ins Archiv gelegt Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
363 lines
15 KiB
Python
363 lines
15 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
katalog_web.py - statische Webseiten aus den Katalogdateien erzeugen
|
||
|
||
Liest aus dem Archiv-Verzeichnis (src):
|
||
Sendungsliste.txt, Themenkatalog.txt, Namensverzeichnis.txt, abstracts.txt,
|
||
jottalinks.txt (Download-Links, optional)
|
||
und schreibt ein statisches Site nach (out, Default: <src>/web):
|
||
index.html, sendungen.html, themen.html, namen.html
|
||
|
||
Aufruf:
|
||
python3 katalog_web.py # src = Skript-Ordner, out = src/web
|
||
python3 katalog_web.py --src DIR --out DIR2 # freie Wahl
|
||
|
||
Kein Build, keine externen Assets - die HTML-Dateien funktionieren offline
|
||
und auf jedem beliebigen Static-Host (Webroot, Gitea Pages, tailscale serve).
|
||
Suche/Filter laufen clientseitig per JavaScript (?q=... in der URL geht auch).
|
||
"""
|
||
|
||
import argparse
|
||
import datetime
|
||
import html
|
||
import os
|
||
import re
|
||
import unicodedata
|
||
|
||
|
||
def esc(s):
|
||
return html.escape(s or "", quote=True)
|
||
|
||
|
||
def sortkey(name):
|
||
return unicodedata.normalize("NFKD", name).encode("ascii", "ignore").decode().lower()
|
||
|
||
|
||
# ---------- Parser ----------
|
||
|
||
def parse_sendungsliste(path):
|
||
"""-> Liste von dicts {nr, datum, titel, ordner}, nach Nummer sortiert."""
|
||
rows = []
|
||
if not os.path.exists(path):
|
||
return rows
|
||
with open(path, encoding="utf-8") as fh:
|
||
for line in fh:
|
||
parts = line.rstrip("\n").split("\t")
|
||
if len(parts) >= 3 and re.match(r"^\d{3}$", parts[0]):
|
||
rows.append({"nr": parts[0], "datum": parts[1],
|
||
"titel": parts[2],
|
||
"ordner": parts[3] if len(parts) > 3 else ""})
|
||
rows.sort(key=lambda r: int(r["nr"]))
|
||
return rows
|
||
|
||
|
||
def parse_themenkatalog(path):
|
||
"""-> (header_lines, [(rubrik, [(nr, titel), ...]), ...]) in Dateireihenfolge."""
|
||
if not os.path.exists(path):
|
||
return [], []
|
||
lines = open(path, encoding="utf-8").read().split("\n")
|
||
header, sections = [], []
|
||
rubrik = None
|
||
eintraege = None
|
||
i = 0
|
||
# Header: alles bis zur ersten Rubrik-Zeile
|
||
while i < len(lines):
|
||
if re.match(r"^.+ \(\d+ (Sendungen|Dateien)", lines[i]) and i + 1 < len(lines) \
|
||
and re.match(r"^-+\s*$", lines[i + 1]):
|
||
break
|
||
header.append(lines[i])
|
||
i += 1
|
||
while i < len(lines):
|
||
line = lines[i]
|
||
if re.match(r"^.+ \(\d+ (Sendungen|Dateien)", line) and i + 1 < len(lines) \
|
||
and re.match(r"^-+\s*$", lines[i + 1]):
|
||
rubrik = line
|
||
eintraege = []
|
||
sections.append((rubrik, eintraege))
|
||
i += 2
|
||
continue
|
||
m = re.match(r"^(\d{3}) - (.*)$", line)
|
||
if m and eintraege is not None:
|
||
eintraege.append((m.group(1), m.group(2)))
|
||
elif line.strip() and eintraege is not None and not line.startswith("-"):
|
||
eintraege.append(("", line.strip())) # Fließtext innerhalb einer Rubrik
|
||
i += 1
|
||
return header, sections
|
||
|
||
|
||
def parse_namensverzeichnis(path):
|
||
"""-> [(name, [nr, ...])] alphabetisch sortiert."""
|
||
persons = {}
|
||
if os.path.exists(path):
|
||
for line in open(path, encoding="utf-8"):
|
||
m = re.match(r"^([^\t]+)\t(.+)$", line.rstrip("\n"))
|
||
if m and not m.group(1).startswith("Nachname"):
|
||
persons[m.group(1)] = re.findall(r"\d{3}", m.group(2))
|
||
return [(name, persons[name]) for name in sorted(persons, key=sortkey)]
|
||
|
||
|
||
def parse_abstracts(path):
|
||
"""-> dict nr -> (titel, abstract_text)."""
|
||
result = {}
|
||
if not os.path.exists(path):
|
||
return result
|
||
nr = None
|
||
titel = ""
|
||
text = []
|
||
for line in open(path, encoding="utf-8").read().split("\n"):
|
||
m = re.match(r"^(\d{3}) \| (.*)$", line)
|
||
if m:
|
||
if nr:
|
||
result[nr] = (titel, "\n".join(text))
|
||
nr, titel, text = m.group(1), m.group(2), []
|
||
elif nr and line.startswith(" "):
|
||
text.append(line[4:])
|
||
if nr:
|
||
result[nr] = (titel, "\n".join(text))
|
||
return result
|
||
|
||
|
||
def parse_jottalinks(path):
|
||
"""-> dict nr -> url. Format: 'NNN<TAB>URL'; #-Kommentare ignoriert,
|
||
nur http(s)-Links werden uebernommen."""
|
||
links = {}
|
||
if not os.path.exists(path):
|
||
return links
|
||
with open(path, encoding="utf-8") as fh:
|
||
for line in fh:
|
||
line = line.rstrip("\n")
|
||
if not line.strip() or line.lstrip().startswith("#"):
|
||
continue
|
||
parts = line.split("\t")
|
||
if len(parts) >= 2 and re.match(r"^\d{3}$", parts[0].strip()):
|
||
url = parts[1].strip()
|
||
if re.match(r"^https?://", url, re.I):
|
||
links[parts[0].strip()] = url
|
||
return links
|
||
|
||
|
||
# ---------- HTML ----------
|
||
|
||
CSS = """
|
||
:root { --bg:#fff; --fg:#1a1a1a; --muted:#666; --line:#e2e2e2; --accent:#7a1f2b;
|
||
--card:#f7f5f2; --hl:#fdf3d8; }
|
||
@media (prefers-color-scheme: dark) {
|
||
:root { --bg:#161618; --fg:#e8e6e3; --muted:#9a9a9a; --line:#333;
|
||
--accent:#e08a96; --card:#1f1f22; --hl:#3a3416; } }
|
||
* { box-sizing:border-box; }
|
||
body { margin:0; background:var(--bg); color:var(--fg);
|
||
font:16px/1.5 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif; }
|
||
header { position:sticky; top:0; background:var(--bg); border-bottom:1px solid var(--line);
|
||
padding:.6rem 1rem; display:flex; gap:.6rem; align-items:center; flex-wrap:wrap; z-index:5; }
|
||
header .brand { font-weight:700; color:var(--accent); text-decoration:none; margin-right:auto; }
|
||
header input[type=search] { flex:1 1 16rem; padding:.45rem .7rem; font-size:1rem;
|
||
border:1px solid var(--line); border-radius:6px; background:var(--bg); color:var(--fg); }
|
||
header select { padding:.45rem .4rem; border:1px solid var(--line); border-radius:6px;
|
||
background:var(--bg); color:var(--fg); }
|
||
nav a { color:var(--fg); text-decoration:none; padding:.3rem .55rem; border-radius:6px; }
|
||
nav a:hover, nav a.active { background:var(--card); }
|
||
main { max-width:1100px; margin:0 auto; padding:1rem; }
|
||
h1 { font-size:1.4rem; } h2 { font-size:1.15rem; margin-top:1.6rem;
|
||
border-bottom:2px solid var(--accent); padding-bottom:.2rem; }
|
||
table { border-collapse:collapse; width:100%; }
|
||
th, td { text-align:left; padding:.35rem .5rem; border-bottom:1px solid var(--line);
|
||
vertical-align:top; }
|
||
th { position:sticky; top:3.2rem; background:var(--bg); }
|
||
tr:hover td { background:var(--card); }
|
||
tr:target td { background:var(--hl); }
|
||
.nr { font-variant-numeric:tabular-nums; white-space:nowrap; color:var(--muted); }
|
||
.ordner { color:var(--muted); font-size:.85rem; white-space:nowrap; }
|
||
details { margin:.15rem 0; } summary { cursor:pointer; color:var(--muted); font-size:.9rem; }
|
||
details p { margin:.3rem 0 .3rem 1rem; color:var(--fg); white-space:pre-line; }
|
||
.cards { display:grid; grid-template-columns:repeat(auto-fit,minmax(220px,1fr)); gap:1rem; margin-top:1.5rem; }
|
||
.card { background:var(--card); border:1px solid var(--line); border-radius:10px; padding:1rem 1.2rem;
|
||
text-decoration:none; color:var(--fg); }
|
||
.card:hover { border-color:var(--accent); }
|
||
.card h2 { border:none; margin:0 0 .3rem; padding:0; }
|
||
.card .count { color:var(--muted); font-size:.9rem; }
|
||
ul.list { list-style:none; padding:0; }
|
||
ul.list li { padding:.3rem .5rem; border-bottom:1px solid var(--line); }
|
||
a { color:var(--accent); }
|
||
footer { max-width:1100px; margin:2rem auto; padding:1rem; color:var(--muted); font-size:.85rem;
|
||
border-top:1px solid var(--line); }
|
||
.tag { display:inline-block; background:var(--card); border:1px solid var(--line);
|
||
border-radius:5px; padding:0 .35rem; font-size:.8rem; color:var(--muted); text-decoration:none; }
|
||
a.dl { display:inline-block; border:1px solid var(--line); border-radius:6px;
|
||
padding:0 .5rem; font-size:.85rem; text-decoration:none; white-space:nowrap; }
|
||
a.dl:hover { border-color:var(--accent); background:var(--card); }
|
||
"""
|
||
|
||
JS = """
|
||
function filter() {
|
||
const q = document.getElementById('q').value.toLowerCase();
|
||
const ord = document.getElementById('ordner');
|
||
const ordv = ord ? ord.value : '';
|
||
document.querySelectorAll('[data-row]').forEach(el => {
|
||
const okq = !q || el.textContent.toLowerCase().includes(q);
|
||
// Wert mit "!" prefix = Negation: "!Prüfen" = alles AUSSER Prüfen ("geprüfte")
|
||
const oko = !ordv ? true
|
||
: ordv.startsWith('!') ? (el.getAttribute('data-ordner') || '') !== ordv.slice(1)
|
||
: (el.getAttribute('data-ordner') || '') === ordv;
|
||
el.style.display = (okq && oko) ? '' : 'none';
|
||
});
|
||
const n = document.querySelectorAll('[data-row]:not([style*="none"])').length;
|
||
const c = document.getElementById('count');
|
||
if (c) c.textContent = n + ' Einträge';
|
||
}
|
||
document.addEventListener('DOMContentLoaded', () => {
|
||
const p = new URLSearchParams(location.search).get('q');
|
||
if (p) { document.getElementById('q').value = p; }
|
||
filter();
|
||
});
|
||
"""
|
||
|
||
|
||
def page(title, body, active, extra_nav=""):
|
||
nav = (f'<a href="index.html"{" class=active" if active=="index" else ""}>Start</a>'
|
||
f'<a href="sendungen.html"{" class=active" if active=="sendungen" else ""}>Sendungen</a>'
|
||
f'<a href="themen.html"{" class=active" if active=="themen" else ""}>Themen</a>'
|
||
f'<a href="namen.html"{" class=active" if active=="namen" else ""}>Personen</a>'
|
||
+ extra_nav)
|
||
return f"""<!DOCTYPE html>
|
||
<html lang="de"><head><meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||
<title>{esc(title)} · Lange-Nacht-Archiv</title>
|
||
<style>{CSS}</style></head><body>
|
||
<header><a class="brand" href="index.html">Lange-Nacht-Archiv</a>
|
||
<nav>{nav}</nav>
|
||
<input id="q" type="search" placeholder="Suchen …" oninput="filter()">
|
||
<span id="count" class="ordner"></span></header>
|
||
<main>{body}</main>
|
||
<footer>Generiert am {datetime.date.today().strftime('%d.%m.%Y')} aus Sendungsliste.txt,
|
||
Themenkatalog.txt, Namensverzeichnis.txt, abstracts.txt und jottalinks.txt · katalog_web.py</footer>
|
||
<script>{JS}</script></body></html>"""
|
||
|
||
|
||
def build_index(out, rows, sections, persons, links):
|
||
n_send = len(rows)
|
||
n_themen = sum(len(e) for _r, e in sections)
|
||
n_mit_abs = len(parse_abstracts(os.path.join(out_src, "abstracts.txt")))
|
||
n_link = sum(1 for r in rows if r["nr"] in links)
|
||
body = f"""
|
||
<h1>Lange Nacht — Aufnahme-Archiv</h1>
|
||
<p>Stöbern in {n_send} aufgenommenen „Lange Nacht“-Sendungen (Deutschlandfunk /
|
||
Deutschlandfunk Kultur): nach <a href="sendungen.html">Nummer</a>,
|
||
<a href="themen.html">Thema</a> oder <a href="namen.html">Person</a>.</p>
|
||
<div class="cards">
|
||
<a class="card" href="sendungen.html"><h2>Sendungsliste</h2>
|
||
<span class="count">{n_send} Sendungen, {n_mit_abs} mit Abstract, {n_link} mit Download-Link</span></a>
|
||
<a class="card" href="themen.html"><h2>Themenkatalog</h2>
|
||
<span class="count">{len(sections)} Rubriken, {n_themen} Einträge</span></a>
|
||
<a class="card" href="namen.html"><h2>Namensverzeichnis</h2>
|
||
<span class="count">{len(persons)} Personen</span></a>
|
||
</div>"""
|
||
return page("Start", body, "index")
|
||
|
||
|
||
def _datum_key(d):
|
||
"""'14.11.2026' -> (2026, 11, 14); '--.--.----' -> None."""
|
||
m = re.match(r"^(\d{2})\.(\d{2})\.(\d{4})$", d or "")
|
||
return (int(m.group(3)), int(m.group(2)), int(m.group(1))) if m else None
|
||
|
||
|
||
def build_sendungen(out, rows, abstracts, links):
|
||
# neueste zuerst, Aufnahmen ohne Datum ganz unten
|
||
dated = [r for r in rows if _datum_key(r["datum"])]
|
||
undated = [r for r in rows if not _datum_key(r["datum"])]
|
||
dated.sort(key=lambda r: (_datum_key(r["datum"]), int(r["nr"])), reverse=True)
|
||
undated.sort(key=lambda r: int(r["nr"]), reverse=True)
|
||
rows = dated + undated
|
||
trs = []
|
||
for r in rows:
|
||
nr = r["nr"]
|
||
abs_titel, abs_text = abstracts.get(nr, ("", ""))
|
||
det = ""
|
||
if abs_text:
|
||
det = (f'<details><summary>Abstract</summary><p>{esc(abs_text)}</p></details>')
|
||
dl = (f'<a class="dl" href="{esc(links[nr])}" target="_blank" rel="noopener" '
|
||
f'title="Download (Jottacloud)">⬇ MP3</a>') if nr in links else ""
|
||
trs.append(
|
||
f'<tr data-row data-ordner="{esc(r["ordner"])}" id="s{nr}">'
|
||
f'<td class="nr">{nr}</td><td class="nr">{esc(r["datum"])}</td>'
|
||
f'<td>{esc(r["titel"])}{det}</td>'
|
||
f'<td class="ordner">{esc(r["ordner"])}</td>'
|
||
f'<td>{dl}</td></tr>')
|
||
body = f"""
|
||
<h1>Sendungsliste</h1>
|
||
<p class="ordner">neueste zuerst; Aufnahmen ohne Datum stehen ganz unten · ⬇ MP3 = Download-Link (Jottacloud)</p>
|
||
<table><thead><tr><th>Nr</th><th>Datum</th><th>Titel</th><th>Ordner</th><th>Download</th></tr></thead>
|
||
<tbody>{''.join(trs)}</tbody></table>"""
|
||
p = page("Sendungen", body, "sendungen")
|
||
# Ordner-Filter einbauen
|
||
ordner = sorted({r["ordner"] for r in rows if r["ordner"]})
|
||
if ordner:
|
||
opts = '<option value="">alle Ordner</option>'
|
||
if "Prüfen" in ordner:
|
||
opts += '<option value="!Prüfen">geprüfte (ohne Prüfen)</option>'
|
||
opts += "".join(f'<option value="{esc(o)}">{esc(o)}</option>' for o in ordner)
|
||
sel = f'<select id="ordner" onchange="filter()">{opts}</select>'
|
||
p = p.replace('<input id="q"', sel + '<input id="q"', 1)
|
||
return p
|
||
|
||
|
||
def build_themen(out, sections):
|
||
parts = []
|
||
for rubrik, eintraege in sections:
|
||
if rubrik.startswith("Anmerkungen"):
|
||
continue
|
||
items = []
|
||
for nr, titel in eintraege:
|
||
if nr:
|
||
items.append(f'<li data-row><a href="sendungen.html#s{nr}">{nr}</a> – {esc(titel)}</li>')
|
||
else:
|
||
items.append(f'<li data-row>{esc(titel)}</li>')
|
||
parts.append(f"<h2>{esc(rubrik)}</h2><ul class='list'>{''.join(items)}</ul>")
|
||
body = f"<h1>Themenkatalog</h1>{''.join(parts)}"
|
||
return page("Themenkatalog", body, "themen")
|
||
|
||
|
||
def build_namen(out, persons):
|
||
items = []
|
||
for name, nrs in persons:
|
||
links = " ".join(f'<a class="tag" href="sendungen.html#s{n}">{n}</a>' for n in nrs)
|
||
items.append(f'<li data-row><strong>{esc(name)}</strong> {links}</li>')
|
||
body = f"<h1>Namensverzeichnis</h1><ul class='list'>{''.join(items)}</ul>"
|
||
return page("Namensverzeichnis", body, "namen")
|
||
|
||
|
||
# ---------- main ----------
|
||
|
||
out_src = "."
|
||
|
||
|
||
def main(src=None, out=None):
|
||
global out_src
|
||
src = src or os.path.dirname(os.path.abspath(__file__))
|
||
out = out or os.path.join(src, "web")
|
||
out_src = src
|
||
os.makedirs(out, exist_ok=True)
|
||
rows = parse_sendungsliste(os.path.join(src, "Sendungsliste.txt"))
|
||
header, sections = parse_themenkatalog(os.path.join(src, "Themenkatalog.txt"))
|
||
persons = parse_namensverzeichnis(os.path.join(src, "Namensverzeichnis.txt"))
|
||
abstracts = parse_abstracts(os.path.join(src, "abstracts.txt"))
|
||
links = parse_jottalinks(os.path.join(src, "jottalinks.txt"))
|
||
with open(os.path.join(out, "index.html"), "w", encoding="utf-8") as fh:
|
||
fh.write(build_index(out, rows, sections, persons, links))
|
||
with open(os.path.join(out, "sendungen.html"), "w", encoding="utf-8") as fh:
|
||
fh.write(build_sendungen(out, rows, abstracts, links))
|
||
with open(os.path.join(out, "themen.html"), "w", encoding="utf-8") as fh:
|
||
fh.write(build_themen(out, sections))
|
||
with open(os.path.join(out, "namen.html"), "w", encoding="utf-8") as fh:
|
||
fh.write(build_namen(out, persons))
|
||
print(f"Web-Katalog geschrieben nach {out}: "
|
||
f"{len(rows)} Sendungen, {len(sections)} Rubriken, {len(persons)} Personen, "
|
||
f"{len(links)} Download-Links.")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
ap = argparse.ArgumentParser()
|
||
ap.add_argument("--src", default=None)
|
||
ap.add_argument("--out", default=None)
|
||
args = ap.parse_args()
|
||
main(args.src, args.out)
|