How to use the hangups.Client function in hangups

To help you get started, we’ve selected a few hangups examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xmikos / qhangups / qhangups / qhangups.py View on Github external
def hangups_start(self):
        """Connect to Hangouts"""
        cookies = self.login(self.cookies_path)
        if cookies:
            self.startHangups.emit()

            self.client = hangups.Client(cookies)
            self.client.on_connect.add_observer(self.on_connect)

            # Run Hangups event loop
            asyncio.async(
                self.client.connect()
            ).add_done_callback(lambda future: future.result())
            self.hangups_running = True
            self.update_status()
github Terrance / IMMP / immp / plug / hangouts.py View on Github external
async def start(self):
        await super().start()
        self._closing = False
        self._client = hangups.Client(hangups.get_auth_stdin(self.config["cookie"]))
        self._client.on_connect.add_observer(self._connect)
        log.debug("Connecting client")
        self._looped = ensure_future(self._loop())
        async with self._starting:
            # Block until users and conversations are loaded.
            await self._starting.wait()
        log.debug("Listening for events")
github xmikos / hangupsbot / hangupsbot / hangupsbot.py View on Github external
def run(self):
        """Connect to Hangouts and run bot"""
        cookies = self.login(self._cookies_path)
        if cookies:
            for retry in range(self._max_retries):
                try:
                    # Create Hangups client
                    self._client = hangups.Client(cookies)
                    self._client.on_connect.add_observer(self._on_connect)
                    self._client.on_disconnect.add_observer(self._on_disconnect)

                    # Start asyncio event loop and connect to Hangouts
                    # If we are forcefully disconnected, try connecting again
                    loop = asyncio.get_event_loop()
                    loop.run_until_complete(self._client.connect())
                    sys.exit(0)
                except Exception as e:
                    print(_('Client unexpectedly disconnected:\n{}').format(e))
                    print(_('Waiting {} seconds...').format(5 + retry * 5))
                    time.sleep(5 + retry * 5)
                    print(_('Trying to connect again (try {} of {})...').format(retry + 1, self._max_retries))
            print(_('Maximum number of retries reached! Exiting...'))
        sys.exit(1)
github elamperti / bastardbot / bot / bot.py View on Github external
def start(self):
        """ Start the loop/bot """
        self.__log.debug("Starting the bot")
        cookies = self.__login()    
        if cookies:
            self.__client = hangups.Client(cookies)
        
            # event handlers
            self.__client.on_connect.add_observer(self.__on_connect)
            self.__client.on_disconnect.add_observer(self.__on_disconnect)

            # asyncio event loop and Hangouts connection with retry logic 
            # If we are forcefully disconnected, try connecting again
            loop = asyncio.get_event_loop()
            for retry in range(self.__max_retries):
                try:
                    loop.run_until_complete(self.__client.connect())
                    sys.exit(0)
                except Exception as e:
                    self.__log.warning("Client unexpectedly disconnected:\n{}".format(e))
                    time.sleep(2)
                    self.__log.warning("Retry {}/{}".format(retry + 1, self.__max_retries))
github davidedmundson / telepathy-hangups / tphangups / connection.py View on Github external
def Connect(self):
        print ("doing connect")
        if self._status == telepathy.CONNECTION_STATUS_DISCONNECTED:
            self.StatusChanged(telepathy.CONNECTION_STATUS_CONNECTING, telepathy.CONNECTION_STATUS_REASON_REQUESTED)
            cookies = hangups.auth.get_auth(None, None, expanduser("~/.hangups_auth_tmp"))
            self._client = hangups.Client(cookies)
            self._client.on_connect.add_observer(self._on_connect)
            asyncio.async(self._client.connect())
github matrix-hacks / matrix-puppet-hangouts / hangups_client.py View on Github external
cookies = hangups.auth.get_auth_stdin(args.token_path)
        #pprint(getmembers(args))
        return
    else:
        # Obtain hangups authentication cookies, prompting for credentials from
        # standard input if necessary.
        refresh_token_cache = RefreshTokenCache(args.token_path)
        try:
            cookies = get_auth(NullCredentialsPrompt(), refresh_token_cache)
        except:
            print("Hangouts login failed. Either you didn't log in yet, or your refresh token expired.\nPlease log in with --login-and-save-token")
            return

    while 1:
        print("Attempting main loop...")
        client = hangups.Client(cookies, max_retries=float('inf'), retry_backoff_base=1.2)
        task = asyncio.ensure_future(_async_main(example_coroutine, client, args))
        loop = asyncio.get_event_loop()

        try:
            loop.run_until_complete(task)
        except KeyboardInterrupt:
            task.cancel()
            loop.run_forever()
        except:
            pass
        finally:
            time.sleep(5)

    try:
        loop.run_until_complete(task)
    except KeyboardInterrupt:
github hangoutsbot / hangoutsbot / hangupsbot / hangupsbot.py View on Github external
def run(self):
        """Connect to Hangouts and run bot"""
        cookies = self.login(self._cookies_path)
        if cookies:
            # Create Hangups client
            self._client = hangups.Client(cookies)
            self._client.on_connect.add_observer(self._on_connect)
            self._client.on_disconnect.add_observer(self._on_disconnect)

            # Initialise hooks
            self._load_hooks()

            # Start asyncio event loop
            loop = asyncio.get_event_loop()

            # Start threads for web sinks
            self._start_sinks(loop)

            # Connect to Hangouts
            # If we are forcefully disconnected, try connecting again
            for retry in range(self._max_retries):
                try: