def token(self): if self._token is None: rv_authorize = self.session.get(self.VK_AUTH_URL, params={ 'client_id': self.VK_APP_ID, 'scope': ",".join(self.VK_SCOPE), 'redirect_uri': self.VK_REDIRECT, 'display': self.VK_DISPLAY, 'v': self.VK_API_VER, 'response_type': 'token' }) form = pq(rv_authorize.content)('form') params = {'email': self.email, 'pass': self.password} for el in form.find('input[type=hidden]'): params[el.name] = el.value rv_login = self.session.post(form.attr('action'), params) action = pq(rv_login.content)('form').attr('action') rv_token = self.session.post(action) matched = re.match('.*access_token=(?P<token>\w+)&', rv_token.url) self._token = Token.create(self._dal_session, data=matched.groupdict()['token']) return self._token
def __init__(self, session, email=None, password=None, ancestor=None): super(VkApi, self).__init__(ancestor) self.email, self.password = email, password self._session = requests.Session() self._dal_session = session self._token = Token.find_one(self._dal_session)