def __init__(self, username, password, httpsession): """Initialize the data object.""" from pyfido import FidoClient self.client = FidoClient(username, password, REQUESTS_TIMEOUT, httpsession) self.data = {}
class FidoData(object): """Get data from Fido.""" def __init__(self, username, password): """Initialize the data object.""" from pyfido import FidoClient self.client = FidoClient(username, password, REQUESTS_TIMEOUT) self.data = {} @Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self): """Get the latest data from Fido.""" from pyfido.client import PyFidoError try: self.client.fetch_data() except PyFidoError as err: _LOGGER.error("Error on receive last Fido data: %s", err) return # Update data self.data = self.client.get_data()
class FidoData(object): """Get data from Fido.""" def __init__(self, number, password): """Initialize the data object.""" from pyfido import FidoClient self.client = FidoClient(number, password, REQUESTS_TIMEOUT) self.data = {} @Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self): """Get the latest data from Fido.""" from pyfido.client import PyFidoError try: self.client.fetch_data() except PyFidoError as err: _LOGGER.error("Error on receive last Fido data: %s", err) return # Update data self.data = self.client.get_data()
class FidoData(object): """Get data from Fido.""" def __init__(self, username, password, httpsession): """Initialize the data object.""" from pyfido import FidoClient self.client = FidoClient(username, password, REQUESTS_TIMEOUT, httpsession) self.data = {} @asyncio.coroutine @Throttle(MIN_TIME_BETWEEN_UPDATES) def async_update(self): """Get the latest data from Fido.""" from pyfido.client import PyFidoError try: yield from self.client.fetch_data() except PyFidoError as exp: _LOGGER.error("Error on receive last Fido data: %s", exp) return False # Update data self.data = self.client.get_data() return True
def main(): """Main function""" parser = argparse.ArgumentParser() parser.add_argument('-u', '--username', required=True, help='Fido username') parser.add_argument('-n', '--number', default=None, required=False, help='Fido phone number') parser.add_argument('-p', '--password', required=True, help='Password') parser.add_argument('-l', '--list', action='store_true', default=False, help='List phone numbers') 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 = FidoClient(args.username, args.password, args.timeout) loop = asyncio.get_event_loop() fut = asyncio.wait([client.fetch_data()]) loop.run_until_complete(fut) if args.list: if not client.get_phone_numbers(): return if args.json: print(json.dumps(client.get_phone_numbers())) else: print("Phone numbers: " "{}".format(", ".join(client.get_phone_numbers()))) else: if not client.get_data(): return if args.json: print(json.dumps(client.get_data())) else: _format_output(args.number, client.get_data()) client.close_session()
def __init__(self, number, password): """Initialize the data object.""" from pyfido import FidoClient self.client = FidoClient(number, password, REQUESTS_TIMEOUT) self.data = {}