#!/usr/bin/python3
""" 
Check both mapper vehicle's batteries, forward and aft,
printing the output to screen of the `STATS` message, and 
repeating until keyboard interrupt.

"""
from sys import exit
from signal import signal, SIGINT
from mapper_checkout import Mapper
import os
from time import sleep

def check_batteries(host):
    with Mapper(host) as mapper:
        mapper.check_aft_battery()
        mapper.check_fwd_battery()

if __name__ == '__main__':

    from argparse import ArgumentParser
    a = ArgumentParser(
        description="Check both mapper vehicle's batteries,\
            forward and aft, printing the output to screen\
            of the `STATS` message, and repeating until\
            keyboard interrupt."
        )
    a.parse_args()

    try: 
        while(True):
            os.system('cls' if os.name == 'nt' else 'clear')
            try: 
                check_batteries('mvc-mb1')
            except:
                print('\t\t\t[INFO]\tCannot reach Mapper 1'.upper())
            try: 
                check_batteries('mvc-mb2')
            except:
                print('\t\t\t[INFO]\tCannot reach Mapper 2'.upper())
            period = 20
            print(f"Sleeping {period} seconds ...")
            sleep(period)
            
    except KeyboardInterrupt:
        print("Exiting...")
        exit(0)
