Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. import pycurl
  2. from urllib.parse import urlencode
  3. from io import BytesIO
  4. import json
  5.  
  6. from bs4 import BeautifulSoup
  7.  
  8.  
  9.  
  10. class Api:
  11. url = 'https://online.mbank.pl';
  12. username = '88817185'
  13. password = 'HASLO'
  14. def __init__(self):
  15.  
  16.  
  17. self.curl = pycurl.Curl()
  18.  
  19. self.curl.setopt(pycurl.POST, 0)
  20. self.curl.setopt(pycurl.FOLLOWLOCATION, 0)
  21. self.curl.setopt(pycurl.SSL_VERIFYPEER, 1)
  22.  
  23. self.curl.setopt(pycurl.SSLVERSION, pycurl.SSLVERSION_TLSv1)
  24. self.curl.setopt(pycurl.PROTOCOLS, pycurl.PROTO_HTTPS)
  25. self.curl.setopt(pycurl.CAINFO, "D:\\si\\crt\\cacert.pem")
  26. self.curl.setopt(pycurl.COOKIEJAR, "null")
  27.  
  28.  
  29. def login(self):
  30. buffer = BytesIO()
  31. self.curl.setopt(pycurl.URL, self.url + '/pl/Login')
  32. self.curl.setopt(pycurl.WRITEFUNCTION, buffer.write)
  33.  
  34. self.curl.perform()
  35.  
  36. buffer = BytesIO()
  37. post_data = {'UserName': self.username, 'Password': self.password, 'Seed': '', 'Lang': ''}
  38. postfields = urlencode(post_data)
  39. self.curl.setopt(pycurl.URL, self.url + '/pl/Account/JsonLogin')
  40. self.curl.setopt(pycurl.POST, 1)
  41. self.curl.setopt(pycurl.WRITEFUNCTION, buffer.write)
  42. self.curl.setopt(self.curl.POSTFIELDS, postfields)
  43.  
  44. self.curl.perform()
  45. body = buffer.getvalue()
  46. status = json.loads(body)
  47. if(status["successful"] != True):
  48. raise Exception("Login failed")
  49. self.tab = status['tabId']
  50. buffer = BytesIO()
  51. self.curl.setopt(pycurl.POST, 0)
  52. self.curl.setopt(pycurl.URL, self.url + '/pl')
  53. self.curl.setopt(pycurl.WRITEFUNCTION, buffer.write)
  54. self.curl.perform()
  55. text = str(buffer.getvalue())
  56. #print(text)
  57. soup = BeautifulSoup(text, "lxml")
  58. self.token = soup.find("meta", {"name":"__AjaxRequestVerificationToken"})["content"]
  59. return True;
  60.  
  61.  
  62.  
  63. def accounts(self):
  64. post_data = {}
  65. buffer = BytesIO()
  66. postfields = urlencode(post_data)
  67. self.curl.setopt(pycurl.URL, self.url + '/pl/MyDesktop/Desktop/GetAccountsList')
  68. self.curl.setopt(pycurl.POST, 1)
  69. self.curl.setopt(pycurl.WRITEFUNCTION, buffer.write)
  70. self.curl.setopt(pycurl.POSTFIELDS, postfields)
  71. self.curl.setopt(pycurl.HTTPHEADER, ['X-Request-Verification-Token: '+self.token, 'X-Tab-Id: '+self.tab, 'X-Requested-With: XMLHttpRequest'])
  72. self.curl.perform()
  73. body = buffer.getvalue()
  74. status = json.loads(body)
  75. return status
  76.  
  77.  
  78. api = Api()
  79. try:
  80. if(api.login()):
  81. print("Login successful")
  82. data = api.accounts()["accountDetailsList"][0]["Balance"]
  83.  
  84.  
  85. print("Balance: "+data+"zl. ")
  86. except Exception as e:
  87. print(str(e))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement