diff --git a/pkgs/additional/sane-weather/sane-weather b/pkgs/additional/sane-weather/sane-weather index 84a84469..11a347e7 100755 --- a/pkgs/additional/sane-weather/sane-weather +++ b/pkgs/additional/sane-weather/sane-weather @@ -39,6 +39,9 @@ class QueryOp: class PrintTempOp: pass +class DiagnosticsOp: + pass + class ExitOp: pass @@ -66,8 +69,14 @@ class TopLevel: if temp is not None: del self.work_queue[0] print(f"{int(temp)} C") + elif isinstance(work, DiagnosticsOp): + del self.work_queue[0] + # GWeather does transparent caching so that we don't usually hit the web + last_update = self.source.info.get_update() + logger.debug(f"last update: {last_update}") elif isinstance(work, ExitOp): logger.debug("quitting GLib MainLoop") + self.source.info.store_cache() self._loop.quit() else: assert False, f"unknown work: {work}" @@ -79,27 +88,32 @@ def main(): logging.basicConfig() parser = argparse.ArgumentParser(description="acquire weather information for user display") - parser.add_argument('--interactive', action='store_true', help='drop into a REPL instead of doing anything, for debugging') - parser.add_argument('--verbose', action='store_true', help='enable verbose logging') #< only applies immediately to this app; use `G_MESSAGES_DEBUG=all` for more verbosity + parser.add_argument('--break-before', action='store_true', help='drop into a REPL before do anything (for debugging)') + parser.add_argument('--break-after', action='store_true', help='drop into a REPL after completing the work (for debugging)') + parser.add_argument('--verbose', action='store_true', help='enable verbose logging') args = parser.parse_args() if args.verbose: logger.setLevel(logging.DEBUG) + GLib.log_set_debug_enabled(True) toplevel = TopLevel() # for now, hardcoded; four-letter station code is that from METAR: # - here = GWeather.Location.find_by_station_code(toplevel.source.world, 'KSEA') - if args.interactive: + if args.break_before: code.interact(local=dict(**globals(), **locals())) - return toplevel.enqueue(QueryOp(here)) toplevel.enqueue(PrintTempOp()) + toplevel.enqueue(DiagnosticsOp()) toplevel.run() + if args.break_after: + code.interact(local=dict(**globals(), **locals())) + if __name__ == '__main__': main()