Beispiel #1
0
def main():
    """Main function"""
    parser = argparse.ArgumentParser()
    parser.add_argument('-u', '--username',
                        required=True, help='EBox account')
    parser.add_argument('-p', '--password',
                        required=True, help='Password')
    parser.add_argument('-j', '--json', action='store_true',
                        default=False, help='Json output')
    parser.add_argument('-t', '--timeout',
                        default=REQUESTS_TIMEOUT, help='Request timeout')
    args = parser.parse_args()
    client = EboxClient(args.username, args.password, args.timeout)

    loop = asyncio.get_event_loop()
    task = loop.create_task(client.fetch_data())
    try:
        loop.run_until_complete(task)
    except PyEboxError as exp:
        print(exp)
        client.close_session()
        return
    if not client.get_data():
        client.close_session()
        return
    if args.json:
        print(json.dumps(client.get_data()))
    else:
        _format_output(args.username, client.get_data())
    client.close_session()
class EBoxData(object):
    """Get data from Ebox."""
    def __init__(self, username, password):
        """Initialize the data object."""
        from pyebox import EboxClient
        self.client = EboxClient(username, password, REQUESTS_TIMEOUT)
        self.data = {}

    def update(self):
        """Get the latest data from Ebox."""
        from pyebox.client import PyEboxError
        try:
            self.client.fetch_data()
        except PyEboxError as exp:
            _LOGGER.error("Error on receive last EBox data: %s", exp)
            return
        self.data = self.client.get_data()
Beispiel #3
0
class EBoxData(object):
    """Get data from Ebox."""

    def __init__(self, username, password):
        """Initialize the data object."""
        from pyebox import EboxClient
        self.client = EboxClient(username, password, REQUESTS_TIMEOUT)
        self.data = {}

    def update(self):
        """Get the latest data from Ebox."""
        from pyebox.client import PyEboxError
        try:
            self.client.fetch_data()
        except PyEboxError as exp:
            _LOGGER.error("Error on receive last EBox data: %s", exp)
            return
        self.data = self.client.get_data()