diff --git a/mbox2web b/mbox2web index f238dc8..cd18196 100755 --- a/mbox2web +++ b/mbox2web @@ -1,5 +1,6 @@ #!/usr/bin/python3 +from collections import defaultdict import datetime import email.header import email.parser @@ -1144,6 +1145,31 @@ class Thread: def subject(self): return list(self.messages.values())[0].subject + def index(self, message): + for i, m in enumerate(sorted(self.messages.values(), key=lambda x: x.date)): + if m == message: + return i + +class Month: + def __init__(self, year, month): + self.year = year + self.month = month + self.threads = defaultdict(int) + + def add(self, thread): + self.threads[thread] += 1 + + @property + def longest_thread(self): + thread = None + maxcount = 0 + for t, c in self.threads.items(): + if c > maxcount: + maxcount = c + thread = t + print("longest_thread: found thread", thread) + return thread + class Archive: def __init__(self): @@ -1215,16 +1241,19 @@ class Archive: def webify_calendar(self): - caltmpl = jenv.get_template("calendar.html") + + ovrtmpl = jenv.get_template("overview.html") + bmotmpl = jenv.get_template("by_month.html") cal = {} for t in self.thread_list: - y = t.date.year - m = t.date.month - if y not in cal: - cal[y] = {} - if m not in cal[y]: - cal[y][m] = [] - cal[y][m].append(t) + for m in t.messages.values(): + y = m.date.year + m = m.date.month + if y not in cal: + cal[y] = {} + if m not in cal[y]: + cal[y][m] = Month(y, m) + cal[y][m].add(t) caldir = basedir + "/cal" os.makedirs(caldir, exist_ok=True) with open(caldir + "/index.html", "w") as hfd: @@ -1232,8 +1261,18 @@ class Archive: "list": "LUGA", "cal": cal, } - calhtml = caltmpl.render(context) + calhtml = ovrtmpl.render(context) hfd.write(calhtml) + for y in cal.keys(): + for m in cal[y].keys(): + monthdir = f"{caldir}/{y}/{m}" + os.makedirs(monthdir, exist_ok=True) + with open(monthdir + "/index.html", "w") as hfd: + context = { + "month": cal[y][m] + } + monthhtml = bmotmpl.render(context) + hfd.write(monthhtml) def self_check(self): diff --git a/templates/by_month.html b/templates/by_month.html new file mode 100644 index 0000000..61bd229 --- /dev/null +++ b/templates/by_month.html @@ -0,0 +1,33 @@ + + + + + + {{list}}: {{month.year}}-{{month.month}} + + + + +

Mailinglist {{list}} {{month.year}}-{{month.month}}

+ +
+ +
+ + + + + diff --git a/templates/overview.html b/templates/overview.html new file mode 100644 index 0000000..86b56f1 --- /dev/null +++ b/templates/overview.html @@ -0,0 +1,39 @@ + + + + + + {{list}}: Overview + + + + +
+

Mailinglist {{list}} nach Datum

+
+ +
+ {% for y in cal | dictsort(reverse=True) %} +

{{y.0}}

+ + + + + + {% for m in y.1 | dictsort(reverse=True) %} + + + + + {% endfor %} +
MonatLängster Thread
{{m.0}}{{m.1.longest_thread.subject}}
+ {% endfor %} +
+ + + + +