Advertisement
Guest User

Untitled

a guest
Apr 11th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. """
  2. Log into beam though the API
  3. """
  4. #!/usr/bin/python3.4
  5.  
  6. from getpass import getpass
  7. from requests import Session
  8. from beam_interactive import start, proto
  9.  
  10. URL = "https://beam.pro/api/v1/"
  11. URL_LOGIN = "/users/login"
  12. URL_INTERACIVE = "/interactive/{channel}/robot"
  13.  
  14. S = Session()
  15.  
  16. USE_2FA = False
  17. AUTHENTICATION = {
  18. "username": "",
  19. "password": "!",
  20. "code": "" # Unnecessary if two-factor authentication is disabled.
  21. }
  22. '''
  23. AUTHENTICATION['username'] = input("Username : ")
  24. AUTHENTICATION['password'] = getpass("Password : ")
  25. if USE_2FA:
  26. while not ((len(AUTHENTICATION['code']) == 6) or
  27. any(c.isalpha() for c in AUTHENTICATION['code'])):
  28.  
  29. AUTHENTICATION['code'] = input("2FA code : ")
  30.  
  31. if (len(AUTHENTICATION['code']) < 6) or (len(AUTHENTICATION['code']) > 6):
  32. print("ERROR: 2FA Code must be 6 characters long")
  33.  
  34. if any(c.isalpha() for c in AUTHENTICATION['code']):
  35. print("ERROR: 2FA Code MUST NOT contain letters or special characters")
  36. '''
  37. def login(username, password, code='', *, session=S):
  38. """Log into Beam via the API."""
  39. auth = dict(username=username, password=password, code=code)
  40. return session.post(URL + URL_LOGIN, data=auth).json
  41.  
  42. channel_id = login('skynet', 'Gordon60', '')["channel"]["id"]
  43.  
  44. print(channel_id)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement