From 5cded5f27c94bd39cbe744c979f8a16f8ab01a56 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Sun, 9 Dec 2018 21:41:09 -0600 Subject: [PATCH] Updated code for the new deletion of methods in vk sessions --- src/sessionmanager/session.py | 22 +--------------------- src/sessionmanager/vkSessionHandler.py | 12 ++---------- 2 files changed, 3 insertions(+), 31 deletions(-) diff --git a/src/sessionmanager/session.py b/src/sessionmanager/session.py index 469774b..6f057d8 100644 --- a/src/sessionmanager/session.py +++ b/src/sessionmanager/session.py @@ -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 diff --git a/src/sessionmanager/vkSessionHandler.py b/src/sessionmanager/vkSessionHandler.py index 39bb8fd..24e39cf 100644 --- a/src/sessionmanager/vkSessionHandler.py +++ b/src/sessionmanager/vkSessionHandler.py @@ -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() \ No newline at end of file