sane-weather: more diagnostics
This commit is contained in:
parent
f945dc42fa
commit
681d3d5520
|
@ -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:
|
||||
# - <https://aviationweather.gov/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()
|
||||
|
|
Loading…
Reference in New Issue
Block a user