2016-02-13 17:06:36 -06:00
|
|
|
#!/usr/bin/python
|
|
|
|
import keys
|
2016-05-10 20:23:48 -05:00
|
|
|
import logging
|
2018-12-09 05:21:52 -06:00
|
|
|
import vk_api
|
|
|
|
from vk_api.audio import VkAudio
|
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()
|
|
|
|
|
|
|
|
def login(self, user, password):
|
2016-05-10 20:23:48 -05:00
|
|
|
log.debug("Logging in vk using user/password authentication")
|
2018-12-09 07:25:30 -06:00
|
|
|
self.session_object = vk_api.VkApi(app_id=self.api_key, login=user, password=password, scope="wall, notify, friends, photos, audio, video, docs, notes, pages, status, groups, messages, notifications, stats")
|
|
|
|
self.session_object.auth()
|
|
|
|
self.client = self.session_object.get_api()
|
2018-12-09 05:21:52 -06:00
|
|
|
# self.client = API(s, v=self.api_version)
|
2016-05-10 20:23:48 -05:00
|
|
|
log.debug("Getting tokens for 24 hours...")
|
2016-02-13 17:06:36 -06:00
|
|
|
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)
|
2016-02-13 17:06:36 -06:00
|
|
|
|
|
|
|
def login_access_token(self, token):
|
2016-05-10 20:23:48 -05:00
|
|
|
log.debug("Logging in VK using stored tokens...")
|
2018-12-09 07:25:30 -06:00
|
|
|
self.session_object = vk_api.VkApi(app_id=self.api_key, token=token, scope="wall, notify, friends, photos, audio, video, docs, notes, pages, status, groups, messages, notifications, stats")
|
|
|
|
self.session_object.auth()
|
|
|
|
self.client = self.session_object.get_api()
|
|
|
|
self.client_audio = VkAudio(self.session_object)
|
2016-02-14 18:46:23 -06:00
|
|
|
return self.client.account.getProfileInfo()
|