Commit Diff


commit - 1b8da529cd559a0ad8667a0408d76a8b51d56f13
commit + 277b69f72662ff7005646785b419f2b0da3d4c33
blob - 1160357735a999d8ec4a8e04596b8784603cf7b0
blob + 1e5d0ad069729550c32d9a0bd3aec1c7132e629a
--- lonk.py
+++ lonk.py
@@ -331,30 +331,39 @@ def page_lonk(lonk_url, honk_url):
     gethonks_answer = honk_url.get("gethonks", page="home")
 
     lonk_page = {}
-    convoy_map = {}
-    for honk in reversed(gethonks_answer.pop("honks")[:100]):
-        convoy = convoy_map.get(honk["Convoy"], honk["Convoy"])
-        if convoy not in lonk_page:
-            if honk.get("RID"):
-                for honk_in_convoy in honk_url.get("gethonks", page="convoy", c=convoy)["honks"]:
-                    if honk_in_convoy["What"] == "honked":
-                        if convoy != honk_in_convoy["Convoy"]:
-                            convoy_map[convoy] = honk_in_convoy["Convoy"]
-                            convoy = honk_in_convoy["Convoy"]
-                        if convoy not in lonk_page:
-                            lonk_page[convoy] = _LonkTreeItem(honk_in_convoy)
-                        break
-                else:
-                    lonk_page[convoy] = _LonkTreeItem(None)
-            else:
-                lonk_page[convoy] = _LonkTreeItem(honk)
+    for honk in reversed(gethonks_answer["honks"]):
+        if honk.get("RID"):
+            lonk_page.setdefault(honk["Convoy"], None)
+        else:
+            lonk_page[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 honk in honk_url.get("gethonks", page="convoy", c=convoy)["honks"]:
+            if honk["What"] == "honked":
+                if convoy != honk["Convoy"]:
+                    correction_map[convoy] = honk["Convoy"]
+                    convoy = honk["Convoy"]
+                if lonk_page.get(convoy) is None:
+                    lonk_page[convoy] = _LonkTreeItem(honk)
+                break
+        else:
+            lonk_page[convoy] = _LonkTreeItem(None)
+
+    for honk in reversed(gethonks_answer.pop("honks")):
         if honk.get("RID"):
-            lonk_page[convoy].thread.append(honk)
+            item = lonk_page.get(correction_map.get(honk["Convoy"], honk["Convoy"]))
+            if item is not None:
+                item.thread.append(honk)
 
     gethonks_answer["honks"] = []
-    for tree_item in reversed(lonk_page.values()):
-        gethonks_answer["honks"] += list(tree_item.iterate_honks())
+    for item in reversed(lonk_page.values()):
+        if item is None:
+            break
+        gethonks_answer["honks"] += list(item.iterate_honks())
 
     print_header("lonk home")
     print_gethonks(gethonks_answer, lonk_url, honk_url)