Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pycurl
- from urllib.parse import urlencode
- from io import BytesIO
- import json
- from bs4 import BeautifulSoup
- class Api:
- url = 'https://online.mbank.pl';
- username = '88817185'
- password = 'HASLO'
- def __init__(self):
- self.curl = pycurl.Curl()
- self.curl.setopt(pycurl.POST, 0)
- self.curl.setopt(pycurl.FOLLOWLOCATION, 0)
- self.curl.setopt(pycurl.SSL_VERIFYPEER, 1)
- self.curl.setopt(pycurl.SSLVERSION, pycurl.SSLVERSION_TLSv1)
- self.curl.setopt(pycurl.PROTOCOLS, pycurl.PROTO_HTTPS)
- self.curl.setopt(pycurl.CAINFO, "D:\\si\\crt\\cacert.pem")
- self.curl.setopt(pycurl.COOKIEJAR, "null")
- def login(self):
- buffer = BytesIO()
- self.curl.setopt(pycurl.URL, self.url + '/pl/Login')
- self.curl.setopt(pycurl.WRITEFUNCTION, buffer.write)
- self.curl.perform()
- buffer = BytesIO()
- post_data = {'UserName': self.username, 'Password': self.password, 'Seed': '', 'Lang': ''}
- postfields = urlencode(post_data)
- self.curl.setopt(pycurl.URL, self.url + '/pl/Account/JsonLogin')
- self.curl.setopt(pycurl.POST, 1)
- self.curl.setopt(pycurl.WRITEFUNCTION, buffer.write)
- self.curl.setopt(self.curl.POSTFIELDS, postfields)
- self.curl.perform()
- body = buffer.getvalue()
- status = json.loads(body)
- if(status["successful"] != True):
- raise Exception("Login failed")
- self.tab = status['tabId']
- buffer = BytesIO()
- self.curl.setopt(pycurl.POST, 0)
- self.curl.setopt(pycurl.URL, self.url + '/pl')
- self.curl.setopt(pycurl.WRITEFUNCTION, buffer.write)
- self.curl.perform()
- text = str(buffer.getvalue())
- #print(text)
- soup = BeautifulSoup(text, "lxml")
- self.token = soup.find("meta", {"name":"__AjaxRequestVerificationToken"})["content"]
- return True;
- def accounts(self):
- post_data = {}
- buffer = BytesIO()
- postfields = urlencode(post_data)
- self.curl.setopt(pycurl.URL, self.url + '/pl/MyDesktop/Desktop/GetAccountsList')
- self.curl.setopt(pycurl.POST, 1)
- self.curl.setopt(pycurl.WRITEFUNCTION, buffer.write)
- self.curl.setopt(pycurl.POSTFIELDS, postfields)
- self.curl.setopt(pycurl.HTTPHEADER, ['X-Request-Verification-Token: '+self.token, 'X-Tab-Id: '+self.tab, 'X-Requested-With: XMLHttpRequest'])
- self.curl.perform()
- body = buffer.getvalue()
- status = json.loads(body)
- return status
- api = Api()
- try:
- if(api.login()):
- print("Login successful")
- data = api.accounts()["accountDetailsList"][0]["Balance"]
- print("Balance: "+data+"zl. ")
- except Exception as e:
- print(str(e))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement