diff --git a/src/sessionmanager/vkSessionHandler.py b/src/sessionmanager/vkSessionHandler.py index 030f467..f6c7e3a 100644 --- a/src/sessionmanager/vkSessionHandler.py +++ b/src/sessionmanager/vkSessionHandler.py @@ -1,10 +1,10 @@ #!/usr/bin/python import keys import logging -import vk_api +import vk_api_patched as vk_api import core from vk_api.audio import VkAudio -import core + log = logging.getLogger("vkSessionHandler") class vkObject(object): diff --git a/src/sessionmanager/vk_api_patched.py b/src/sessionmanager/vk_api_patched.py new file mode 100644 index 0000000..f5da838 --- /dev/null +++ b/src/sessionmanager/vk_api_patched.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +""" this is a patched version of vk_api to use a different user agent for authenticating against VK. +Everything else looks the same, the only change in the module is the new user agent, emulating a kate mobile session.""" +import logging +import vk_api +import threading +import requests +import jconfig +from vk_api.enums import VkUserPermissions +from vk_api.exceptions import * + +DEFAULT_USER_SCOPE = sum(VkUserPermissions) + +class VkApi(vk_api.VkApi): + + def __init__(self, login=None, password=None, token=None, + auth_handler=None, captcha_handler=None, + config=jconfig.Config, config_filename='vk_config.v2.json', + api_version='5.92', app_id=6222115, scope=DEFAULT_USER_SCOPE, + client_secret=None): + + self.login = login + self.password = password + + self.token = {'access_token': token} + + self.api_version = api_version + self.app_id = app_id + self.scope = scope + self.client_secret = client_secret + + self.storage = config(self.login, filename=config_filename) + + self.http = requests.Session() + self.http.headers.update({'User-agent': 'KateMobileAndroid/47-427 (Android 6.0.1; SDK 23; armeabi-v7a; samsung SM-G900F; ru)'}) + + self.last_request = 0.0 + + self.error_handlers = { + NEED_VALIDATION_CODE: self.need_validation_handler, + CAPTCHA_ERROR_CODE: captcha_handler or self.captcha_handler, + TOO_MANY_RPS_CODE: self.too_many_rps_handler, + TWOFACTOR_CODE: auth_handler or self.auth_handler + } + + self.lock = threading.Lock() + + self.logger = logging.getLogger('vk_api_patched') + self.logger.info('Started patched VK API client...') \ No newline at end of file