2016-02-13 17:06:36 -06:00
|
|
|
#!/usr/bin/python
|
|
|
|
import keys
|
2016-05-10 20:23:48 -05:00
|
|
|
import logging
|
2016-02-13 17:06:36 -06:00
|
|
|
from vk import API, AuthSession, Session
|
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()
|
2016-02-23 17:49:55 -06:00
|
|
|
self.api_version = 5.45
|
2016-05-10 20:23:48 -05:00
|
|
|
log.debug("Created vkSession using VK API Version %s" % (self.api_version,))
|
2016-02-13 17:06:36 -06:00
|
|
|
|
|
|
|
def login(self, user, password):
|
2016-05-10 20:23:48 -05:00
|
|
|
log.debug("Logging in vk using user/password authentication")
|
2016-02-13 17:06:36 -06:00
|
|
|
s = AuthSession(app_id=self.api_key, user_login=user, user_password=password, scope="wall, notify, friends, photos, audio, video, docs, notes, pages, status, groups, messages, notifications, stats")
|
2016-02-23 17:49:55 -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()
|
|
|
|
|
|
|
|
def login_access_token(self, token):
|
2016-05-10 20:23:48 -05:00
|
|
|
log.debug("Logging in VK using stored tokens...")
|
2016-02-13 17:06:36 -06:00
|
|
|
s = Session(access_token=token)
|
2016-02-23 17:49:55 -06:00
|
|
|
self.client = API(s, v=self.api_version)
|
2016-02-14 18:46:23 -06:00
|
|
|
return self.client.account.getProfileInfo()
|