def main() -> None: """Runs the script.""" args = get_args() loglevel = DEBUG if args.debug else INFO if args.verbose else WARNING basicConfig(format=LOG_FORMAT, level=loglevel) LOGGER.info('Retrieving systems.') with ErrorHandler('Error during JSON data retrieval.'): systems = get_systems(args) for system in filter_systems(systems, args): print(system.get('id'))
def systems_from_cache(args: Namespace) -> list: """Returns cached systems.""" if not args.cache_file.exists(): LOGGER.info('Initializing cache.') systems = query_systems(*update_credentials(args.user)) return cache_systems(systems, args) LOGGER.debug('Loading cache.') with args.cache_file.open('r') as file: cache = load(file) if timestamp := cache.get('timestamp'): timestamp = datetime.fromisoformat(timestamp) if timestamp + timedelta(hours=args.cache_time) > datetime.now(): return cache['systems'] LOGGER.info('Cache has expired.')