| @@ -79,13 +79,16 @@ def main ( | |||||
| if now_m - last_flags_poll >= 10: | if now_m - last_flags_poll >= 10: | ||||
| last_flags_poll = now_m | last_flags_poll = now_m | ||||
| log (f"balloon: { balloon.enabled }, snack: { snack_time.enabled }") | |||||
| try: | try: | ||||
| DB.begin_transaction () | DB.begin_transaction () | ||||
| answer_flags = (AnsweredFlag.where ('platform', Platform.YOUTUBE.value) | answer_flags = (AnsweredFlag.where ('platform', Platform.YOUTUBE.value) | ||||
| .where ('answered', False) | .where ('answered', False) | ||||
| .get ()) | .get ()) | ||||
| log (f"pending: { len (answer_flags) }") | |||||
| if answer_flags: | if answer_flags: | ||||
| answer_flag = random.choice (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) | answer = Answer.find (answer_flag.answer_id) | ||||
| match QueryType (answer.query_rel.query_type): | match QueryType (answer.query_rel.query_type): | ||||
| case QueryType.YOUTUBE_COMMENT: | case QueryType.YOUTUBE_COMMENT: | ||||
| @@ -102,12 +105,14 @@ def main ( | |||||
| DB.commit () | DB.commit () | ||||
| except Exception as ex: | except Exception as ex: | ||||
| DB.rollback () | DB.rollback () | ||||
| log ('EXCEPTION in poll loop') | |||||
| print (ex) | print (ex) | ||||
| try: | try: | ||||
| if broadcast is not None: | if broadcast is not None: | ||||
| add_query (broadcast) | add_query (broadcast) | ||||
| except Exception as ex: | except Exception as ex: | ||||
| log ('EXCEPTION in adding a query') | |||||
| print (ex) | print (ex) | ||||
| game.redraw () | game.redraw () | ||||
| @@ -998,5 +1003,12 @@ def add_query ( | |||||
| DB.commit () | DB.commit () | ||||
| def log ( | |||||
| msg: str, | |||||
| ) -> None: | |||||
| print (f"[{ datetime.now ().isoformat (sep = ' ', timespec = 'seconds') }] { msg }", | |||||
| flush = True) | |||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||
| main () | main () | ||||