2016-02-13 17:06:36 -06:00
|
|
|
#!/usr/bin/python
|
|
|
|
import keys
|
2016-05-10 20:23:48 -05:00
|
|
|
import logging
|
2019-01-19 23:20:51 -06:00
|
|
|
from authenticator import official
|
2018-12-09 05:21:52 -06:00
|
|
|
from vk_api.audio import VkAudio
|
2019-01-19 23:20:51 -06:00
|
|
|
from authenticator.wxUI import two_factor_auth
|
2018-12-17 21:55:26 -06:00
|
|
|
|
2016-05-10 20:23:48 -05:00
|
|
|
log = logging.getLogger("vkSessionHandler")
|
2016-02-13 17:06:36 -06:00
|
|
|
|
|
|
|
class vkObject(object):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.api_key = keys.keyring.get_api_key()
|
|
|
|
|
2019-01-19 23:20:51 -06:00
|
|
|
def login(self, user, password, token, secret, device_id, alt_token, filename):
|
2018-12-15 21:09:17 -06:00
|
|
|
if alt_token == False:
|
|
|
|
log.info("Using kate's token...")
|
2018-12-19 17:34:28 -06:00
|
|
|
# Let's import the patched vk_api module for using a different user agent
|
2019-01-01 19:42:53 -06:00
|
|
|
from . import vk_api_patched as vk_api
|
2018-12-15 21:09:17 -06:00
|
|
|
if token == "" or token == None:
|
|
|
|
log.info("Token is not valid. Generating one...")
|
2019-01-19 23:20:51 -06:00
|
|
|
original_token = official.login(user, password)
|
2019-01-18 17:22:24 -06:00
|
|
|
token = original_token[0]
|
|
|
|
secret = original_token[1]
|
|
|
|
device_id = original_token[2]
|
2018-12-15 21:09:17 -06:00
|
|
|
log.info("Token validated...")
|
2019-01-18 17:22:24 -06:00
|
|
|
self.session_object = vk_api.VkApi(app_id=self.api_key, login=user, password=password, token=token, secret=secret, device_id=device_id, scope="offline, wall, notify, friends, photos, audio, video, docs, notes, pages, status, groups, messages, notifications, stats", config_filename=filename)
|
2018-12-15 21:09:17 -06:00
|
|
|
else:
|
2018-12-19 17:34:28 -06:00
|
|
|
import vk_api
|
|
|
|
self.session_object = vk_api.VkApi(app_id=self.api_key, login=user, password=password, scope="offline, wall, notify, friends, photos, audio, video, docs, notes, pages, status, groups, messages, notifications, stats", config_filename=filename, auth_handler=two_factor_auth)
|
2018-12-17 17:01:37 -06:00
|
|
|
self.session_object.auth()
|
2018-12-09 07:25:30 -06:00
|
|
|
self.client = self.session_object.get_api()
|
2018-12-15 21:09:17 -06:00
|
|
|
# print self.client.audio.get()
|
2016-05-10 20:23:48 -05:00
|
|
|
log.debug("Getting tokens for 24 hours...")
|
2018-12-14 15:30:44 -06:00
|
|
|
# info = self.client.account.getProfileInfo()
|
2018-11-05 10:04:02 -06:00
|
|
|
# Add session data to the application statistics.
|
|
|
|
self.client.stats.trackVisitor()
|
2018-12-09 07:25:30 -06:00
|
|
|
self.client_audio = VkAudio(self.session_object)
|