Updated code for the new deletion of methods in vk sessions

This commit is contained in:
Manuel Cortez 2018-12-09 21:41:09 -06:00
parent 39d1663fa1
commit 5cded5f27c
2 changed files with 3 additions and 31 deletions

View File

@ -90,28 +90,8 @@ class vkSession(object):
# log.exception("The session configuration has failed.")
def login(self):
""" Login using credentials from settings.
if the user account isn't authorised, it'll call self.authorise() before login.
If the access_token has expired, it will call authorise() too, for getting a new access token."""
if self.settings["vk"]["token"] != None:
# Handle special case where you get identical access tokens for two IP addresses.
# See https://github.com/manuelcortez/socializer/issues/11
try:
result = self.vk.login_access_token(self.settings["vk"]["token"])
self.logged = True
log.debug("Logged.")
if result == False:
self.authorise()
except LoginRequired:
self.authorise()
else:
self.authorise()
self.get_my_data()
def authorise(self):
try:
self.vk.login(self.settings["vk"]["user"], self.settings["vk"]["password"])
self.vk.login(self.settings["vk"]["user"], self.settings["vk"]["password"], filename=paths.config_path(self.session_id+"/vkconfig.json"))
self.settings["vk"]["token"] = self.vk.client._session.access_token
self.settings.write()
self.logged = True

View File

@ -10,9 +10,9 @@ class vkObject(object):
def __init__(self):
self.api_key = keys.keyring.get_api_key()
def login(self, user, password):
def login(self, user, password, filename):
log.debug("Logging in vk using user/password authentication")
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 = 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", config_filename=filename)
self.session_object.auth()
self.client = self.session_object.get_api()
# self.client = API(s, v=self.api_version)
@ -21,11 +21,3 @@ class vkObject(object):
# Add session data to the application statistics.
self.client.stats.trackVisitor()
self.client_audio = VkAudio(self.session_object)
def login_access_token(self, token):
log.debug("Logging in VK using stored tokens...")
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)
return self.client.account.getProfileInfo()