Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, database):
self.__db = database
#self.__authors = []
#for author in self.__db.get_authors():
# self.__authors.append(self.__db.dict_factory(author))
# auth cookie
try:
cookies = hangups.auth.get_auth_stdin('cookies')
except auth.GoogleAuthError as e:
print('Login failed ({})'.format(e))
sys.exit(-1)
# init client
self.__client = hangups.client.Client(cookies)
# hooks
self.__client.on_connect.add_observer(self.__on_connect)
self.__client.on_disconnect.add_observer(self.__on_disconnect)
def login(self, cookies_path):
"""Login to Google account"""
# Authenticate Google user and save auth cookies
# (or load already saved cookies)
try:
cookies = hangups.auth.get_auth_stdin(cookies_path)
return cookies
except hangups.GoogleAuthError as e:
print(_('Login failed ({})').format(e))
return False
def login(self, cookies_path):
"""Login to Google account"""
# Authenticate Google user and save auth cookies
# (or load already saved cookies)
try:
cookies = hangups.auth.get_auth_stdin(cookies_path)
return cookies
except hangups.GoogleAuthError as e:
print('Login failed ({})'.format(e))
return False
def main():
"""Start an example chat client."""
client = DemoClient()
cookies = auth.get_auth_stdin('cookies.json')
yield client.connect(cookies)
try:
# disable input line-buffering
curses.initscr()
#curses.nonl()
#curses.cbreak()
yield client.run_forever()
finally:
pass
#curses.nocbreak()
curses.endwin()
def login(self, cookies_path):
"""Login to Google account"""
# Authenticate Google user and save auth cookies
# (or load already saved cookies)
try:
cookies = hangups.auth.get_auth_stdin(cookies_path)
return cookies
except hangups.GoogleAuthError as e:
print('Login failed ({})'.format(e))
return False
def run_example(example_coroutine, *extra_args):
"""Run a hangups example coroutine.
Args:
example_coroutine (coroutine): Coroutine to run with a connected
hangups client and arguments namespace as arguments.
extra_args (str): Any extra command line arguments required by the
example.
"""
args = _get_parser().parse_args()
logging.basicConfig(level=logging.DEBUG if args.debug else logging.WARNING)
if args.login_and_save_token:
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))