Browse Source

fix persistent logon recipe

[ci skip]
pull/50/head
Rossen Georgiev 9 years ago
parent
commit
53bdf71b4a
  1. 18
      recipes/1.Login/persistent_login.py

18
recipes/1.Login/persistent_login.py

@ -1,4 +1,3 @@
from __future__ import handle_function
import logging import logging
import gevent import gevent
from getpass import getpass from getpass import getpass
@ -14,7 +13,7 @@ logon_details = {
"username": raw_input("Steam user: "), "username": raw_input("Steam user: "),
"password": getpass("Password: "), "password": getpass("Password: "),
} }
logged_on_once = False
client = SteamClient() client = SteamClient()
client.set_credential_location(".") client.set_credential_location(".")
@ -29,6 +28,8 @@ def send_login():
client.relogin() client.relogin()
else: else:
client.login(**logon_details) client.login(**logon_details)
logon_details.pop('auth_code', None)
logon_details.pop('two_factor_code', None)
@client.on("connected") @client.on("connected")
def handle_connected(): def handle_connected():
@ -42,9 +43,7 @@ def handle_reconnect(delay):
def handle_disconnect(): def handle_disconnect():
LOG.info("Disconnected.") LOG.info("Disconnected.")
try: if logged_on_once:
client.wait_event("auth_code_required", timeout=2, raises=True)
except:
LOG.info("Reconnecting...") LOG.info("Reconnecting...")
client.reconnect(maxdelay=30) client.reconnect(maxdelay=30)
@ -55,13 +54,18 @@ def auth_code_prompt(is_2fa, mismatch):
if is_2fa: if is_2fa:
code = raw_input("Enter 2FA Code: ") code = raw_input("Enter 2FA Code: ")
client.login(two_factor_code=code, **logon_details) logon_details['two_factor_code'] = code
else: else:
code = raw_input("Enter Email Code: ") code = raw_input("Enter Email Code: ")
client.login(auth_code=code, **logon_details) logon_details['auth_code'] = code
client.connect()
@client.on("logged_on") @client.on("logged_on")
def handle_after_logon(): def handle_after_logon():
global logged_on_once
logged_on_once = True
LOG.info("-"*30) LOG.info("-"*30)
LOG.info("Logged on as: %s", client.user.name) LOG.info("Logged on as: %s", client.user.name)
LOG.info("Community profile: %s", client.steam_id.community_url) LOG.info("Community profile: %s", client.steam_id.community_url)

Loading…
Cancel
Save