Commit Diff


commit - 640fbe968b9493dd3f0dbadad4e16b4ce02449cc
commit + 5dfecba48451268d4842d3521a9fd25660e89a7a
blob - 99fe845c3f87b8ff0db7ced612f02ea1db0a5a03
blob + e3aeb0945fe0a42d28918dc2047a96c13811ac0d
--- lonk.py
+++ lonk.py
@@ -317,7 +317,7 @@ def print_gethonks(gethonks_answer, lonk_url, honk_url
 
 
 class _LonkTreeItem:
-    def __init__(self, honk=None):
+    def __init__(self, honk):
         self.honk = honk
         self.thread = []
 
@@ -330,39 +330,37 @@ class _LonkTreeItem:
 def page_lonk(lonk_url, honk_url):
     gethonks_answer = honk_url.get("gethonks", page="home")
 
-    lonk_page = {}
+    timeline = {}
     for honk in reversed(gethonks_answer["honks"]):
         if honk.get("RID"):
-            lonk_page.setdefault(honk["Convoy"], None)
+            timeline.setdefault(honk["Convoy"], _LonkTreeItem(None))
         else:
-            lonk_page[honk["Convoy"]] = _LonkTreeItem(honk)
+            timeline[honk["Convoy"]] = _LonkTreeItem(honk)
 
     correction_map = {}
-    for convoy in list(reversed([convoy for convoy, item in lonk_page.items() if item is None]))[:36]:
-        convoy = correction_map.get(convoy, convoy)
-        if lonk_page.get(convoy) is not None:
-            continue
+    for convoy in list(reversed([convoy for convoy, item in timeline.items() if item.honk is None]))[:36]:
         for honk in honk_url.get("gethonks", page="convoy", c=convoy)["honks"]:
             if honk["What"] == "honked":
-                if convoy != honk["Convoy"]:
+                if convoy != honk["Convoy"] and honk["Convoy"] in timeline:
                     correction_map[convoy] = honk["Convoy"]
-                    lonk_page[convoy] = _LonkTreeItem(None)
+                    timeline.pop(convoy)
                     convoy = honk["Convoy"]
-                if lonk_page.get(convoy) is None:
-                    lonk_page[convoy] = _LonkTreeItem(honk)
+                if timeline[convoy].honk is None:
+                    timeline[convoy].honk = honk
                 break
         else:
-            lonk_page[convoy] = _LonkTreeItem(None)
+            timeline.pop(convoy)
 
     for honk in reversed(gethonks_answer.pop("honks")):
-        if honk.get("RID"):
-            item = lonk_page.get(correction_map.get(honk["Convoy"], honk["Convoy"]))
-            if item is not None:
-                item.thread.append(honk)
+        if not honk.get("RID"):
+            continue
+        convoy = correction_map.get(honk["Convoy"], honk["Convoy"])
+        if convoy in timeline:
+            timeline[convoy].thread.append(honk)
 
     gethonks_answer["honks"] = []
-    for item in reversed(lonk_page.values()):
-        if item is None:
+    for item in reversed(timeline.values()):
+        if item.honk is None:
             break
         gethonks_answer["honks"] += list(item.iterate_honks())