Pouknouki

Fak

Jul 30th, 2016
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.13 KB | None | 0 0
  1. '''
  2.  
  3. This is a Login example script
  4.  
  5. Can be used as a Log In module for your project as it generates a pickle file for keeping the Login stored
  6.  
  7.  
  8. A basic LogIn flow is:
  9.  
  10. 1. Define the details dictionary, username and password are required
  11. 2. LogIn with the given details, according to steam, one of 4 exceptions will be raised:
  12.    - TwoFactorCodeRequired: Self explanatory, add the 'twoFactorCode' key to the details
  13.      dictionary and try logging in again
  14.    - CaptchaRequiredException: This is a tricky one, a captcha GUID will be stored to the Login object,
  15.      while the exception will return the URL on the message. You must solve the captcha and put the
  16.      "captcha_text" key onto the dict in order to log in again. This is handled very roughly by the example
  17.    - EmailAuthException: Just like the TwoFactorCodeRequired exception but with email
  18. 3. If auth was successful the Login.requests.cookies object will have the session and steam can be used as normal
  19.  
  20. '''
  21.  
  22. import SteamLogin, SteamMobileAuth, pickle
  23.  
  24.  
  25. try:
  26.     with open("Login.pickle") as f:
  27.         print "coucou"
  28.         Login = pickle.load(f)
  29.         assert isinstance(Login, SteamLogin.SteamLogin), "fak"
  30.         print Login._getSteamID()
  31. except IOError:
  32.     details = {
  33.         "username":raw_input(),
  34.         "password":raw_input(),
  35.         "shared_secret":"secret",
  36.         }
  37.     system.stdout.write("No file")
  38.     system.sdout.flush()
  39.     Login = SteamLogin.SteamLogin()
  40.     offset = SteamMobileAuth.getTimeOffset()
  41.     while True:
  42.         try:
  43.             Login.login(details)
  44.             break
  45.         except SteamLogin.TwoFactorCodeRequiredException:
  46.             details['twoFactorCode'] = raw_input()
  47.         except SteamLogin.CaptchaRequiredException as e:
  48.             print e
  49.             details['captcha'] = raw_input()
  50.         except SteamLogin.EmailAuthException as e:
  51.             print(e)
  52.         except SteamLogin.TooManyRequestsException as e:
  53.             print "Retrying after " + e.retryafter+5 + " seconds"
  54.             time.sleep(e.retryafter+5)
  55.         with open("Login.pickle",'wb') as f:
  56.             pickle.dump(Login,f)
Advertisement
Add Comment
Please, Sign In to add comment