From 7daee34ab12ab99788f06fc06ec255c55e679c2c Mon Sep 17 00:00:00 2001 From: miteruzo Date: Sat, 3 Jan 2026 03:48:04 +0900 Subject: [PATCH 1/3] #40 --- main.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 6d2b1f5..7474db5 100644 --- a/main.py +++ b/main.py @@ -55,10 +55,11 @@ def main ( snack_time = SnackTime (game) CurrentTime (game, DEERJIKA_FONT) + broadcast: Broadcast | None = None try: broadcast = Broadcast (os.environ['BROADCAST_CODE']) - except Exception: - pass + except KeyError: + broadcast = None waiting_balloon = (False, '', '') last_flags_poll: float = 0 @@ -99,10 +100,15 @@ def main ( answer_flag.answered = True answer_flag.save () DB.commit () - add_query (broadcast) except Exception as ex: DB.rollback () print (ex) + + try: + if broadcast is not None: + add_query (broadcast) + except Exception as ex: + print (ex) game.redraw () @@ -582,8 +588,9 @@ class Balloon (GameObject): query = self.query if CommonModule.len_by_full (query) > 21: query = CommonModule.mid_by_full (query, 0, 19.5) + '...' - answer = Surface ((375, ((CommonModule.len_by_full (self.answer) - 1) // 16 + 1) * 23.4375), - pygame.SRCALPHA) + answer = Surface ( + (375, int (((CommonModule.len_by_full (self.answer) - 1) // 16 + 1) * 23.4375)), + pygame.SRCALPHA) for i in range (int (CommonModule.len_by_full (self.answer) - 1) // 16 + 1): answer.blit (DEERJIKA_FONT.render ( CommonModule.mid_by_full (self.answer, 16 * i, 16), True, (192, 0, 0)), -- 2.34.1 From af60b8d9a4e3dba62718e12c7531f91cbb1d9249 Mon Sep 17 00:00:00 2001 From: miteruzo Date: Sat, 3 Jan 2026 03:58:08 +0900 Subject: [PATCH 2/3] #40 --- main.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/main.py b/main.py index 7474db5..8d1cfc0 100644 --- a/main.py +++ b/main.py @@ -79,13 +79,16 @@ def main ( if now_m - last_flags_poll >= 10: last_flags_poll = now_m + log (f"balloon: { balloon.enabled }, snack: { snack_time.enabled }") try: DB.begin_transaction () answer_flags = (AnsweredFlag.where ('platform', Platform.YOUTUBE.value) .where ('answered', False) .get ()) + log (f"pending: { len (answer_flags) }") if answer_flags: answer_flag = random.choice (answer_flags) + log (f"flag_id: { answer_flag.id }, answer_id: { answer_flag.answer_id }") answer = Answer.find (answer_flag.answer_id) match QueryType (answer.query_rel.query_type): case QueryType.YOUTUBE_COMMENT: @@ -102,12 +105,14 @@ def main ( DB.commit () except Exception as ex: DB.rollback () + log ('EXCEPTION in poll loop') print (ex) try: if broadcast is not None: add_query (broadcast) except Exception as ex: + log ('EXCEPTION in adding a query') print (ex) game.redraw () @@ -998,5 +1003,12 @@ def add_query ( DB.commit () +def log ( + msg: str, +) -> None: + print (f"[{ datetime.now ().isoformat (sep = ' ', timespec = 'seconds') }] { msg }", + flush = True) + + if __name__ == '__main__': main () -- 2.34.1 From 1c61d9066282b2c8e8b91c4d74d39d5c7314110b Mon Sep 17 00:00:00 2001 From: miteruzo Date: Sat, 3 Jan 2026 04:41:04 +0900 Subject: [PATCH 3/3] #40 --- main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 8d1cfc0..65dc95f 100644 --- a/main.py +++ b/main.py @@ -63,6 +63,7 @@ def main ( waiting_balloon = (False, '', '') last_flags_poll: float = 0 + traced_af_ids: list[int] = [] while True: now_m = time.monotonic () @@ -77,13 +78,14 @@ def main ( deerjika.talk (waiting_balloon[1], waiting_balloon[2]) waiting_balloon = (False, '', '') - if now_m - last_flags_poll >= 10: + if now_m - last_flags_poll >= 1: last_flags_poll = now_m log (f"balloon: { balloon.enabled }, snack: { snack_time.enabled }") try: DB.begin_transaction () answer_flags = (AnsweredFlag.where ('platform', Platform.YOUTUBE.value) .where ('answered', False) + .where_not_in ('id', traced_af_ids) .get ()) log (f"pending: { len (answer_flags) }") if answer_flags: @@ -102,6 +104,8 @@ def main ( waiting_balloon = (True, query.content, answer.content) answer_flag.answered = True answer_flag.save () + case _: + traced_af_ids.append (answer_flag.id) DB.commit () except Exception as ex: DB.rollback () -- 2.34.1