commit 6c43924a03e4d318b0e627f6228b3af226a4bbad from: Aleksey Ryndin date: Tue Oct 01 07:04:27 2024 UTC Fix: exclude reason from db commit - 4e7950e1115bb33752f83affbb29a755bff439bc commit + 6c43924a03e4d318b0e627f6228b3af226a4bbad blob - 590430b8eccd03bcfd3f3c2d834c5b4e9c6b9607 blob + 7b305f84c4fc56b2a9cf62f4d3b19fd73a3ee5cc --- lonk.py +++ lonk.py @@ -303,6 +303,8 @@ class _Collected: self.html = html self.date = date self._donks = None + self._reason_thread = [] + self._reason_repost = [] def add_donk(self, donk_url, mime, alt_text): if self._donks is None: @@ -329,15 +331,44 @@ class _Collected: return yield from donks + + def add_reason_thread(self, reason): + if reason not in self._reason_thread: + self._reason_thread.append(reason) + + def add_reason_repost(self, reason): + if reason not in self._reason_repost: + self._reason_repost.append(reason) + + def format_reason(self): + repost = ", ".join(reason for reason in self._reason_repost) + thread = ", ".join(thread for thread in self._reason_thread) + rv = "" + if repost: + rv += f" (๐Ÿ” {repost})" + if thread: + rv += f" (๐Ÿงต {thread})" + return rv + def _lonk_impl(db_con, client_id, lonk_url, honk_url): fn_media_url = _proxy_url_factory(environ.get("LONK_PROXY_MEDIA"), lonk_url) home = honk_url.do_get(action="gethonks", page="home") lonk_page = {} for honk in reversed(home.get("honks") or []): + if honk.get("RID"): + reason_fn = _Collected.add_reason_thread + reason = honk["Handle"] + else: + reason_fn = _Collected.add_reason_repost + oondle = honk.get("Oondle") + reason = honk["Handle"] if oondle else None + convoy = honk["Convoy"] if convoy in lonk_page: + if reason_fn and reason: + reason_fn(lonk_page[convoy], reason) continue row = db_con.execute( @@ -346,6 +377,8 @@ def _lonk_impl(db_con, client_id, lonk_url, honk_url): ).fetchone() if row: lonk_page[convoy] = _Collected(*row) + if reason_fn and reason: + reason_fn(lonk_page[convoy], reason) continue def _save_convoy(convoy, honker, honk): @@ -378,9 +411,10 @@ def _lonk_impl(db_con, client_id, lonk_url, honk_url): if honk.get("RID"): for honk_in_convoy in honk_url.do_get(action="gethonks", page="convoy", c=convoy)["honks"]: if not honk_in_convoy.get("RID"): - author = honk_in_convoy.get("Oondle") or honk_in_convoy["Handle"] - honker = f'{author} (๐Ÿงต {honk["Handle"]})' + honker = honk_in_convoy.get("Oondle") or honk_in_convoy["Handle"] _save_convoy(convoy, honker, honk_in_convoy) + if reason_fn and reason: + reason_fn(lonk_page[convoy], reason) break else: row = db_con.execute( @@ -397,9 +431,10 @@ def _lonk_impl(db_con, client_id, lonk_url, honk_url): convoy_id, = row lonk_page[convoy] = _Collected(convoy_id, convoy, None, None, None, None, None) else: - oondle = honk.get("Oondle") - honker = f'{oondle} (๐Ÿ” {honk["Handle"]})' if oondle else f'{honk["Handle"]}' + honker = honk.get("Oondle") or honk["Handle"] _save_convoy(convoy, honker, honk) + if reason_fn and reason: + reason_fn(lonk_page[convoy], reason) print("20 text/gemini\r") print("# ๐“— onk\r") @@ -420,7 +455,7 @@ def _lonk_impl(db_con, client_id, lonk_url, honk_url): if collected.honker is None: continue lines = [ - f"## From {collected.honker} {collected.date}", + f"## From {collected.honker}{collected.format_reason()} {collected.date}", f"=> {collected.url}", HtmlToGmi(honk_url.build_url(), fn_media_url).feed(collected.html) ]