Replaced VK with vk_api

This commit is contained in:
Manuel Cortez 2018-12-09 05:21:52 -06:00
parent 1a79e7149c
commit bb26d45f1d
4 changed files with 31 additions and 19 deletions

View File

@ -10,10 +10,10 @@
* Added basic tagging for users in posts and comments. You can tag only people in your friends buffer. * Added basic tagging for users in posts and comments. You can tag only people in your friends buffer.
* Added a basic user profile viewer. * Added a basic user profile viewer.
* Added support for listening voice messages in chats. Currently it is not possible to send them, until the new API will be released. * Added support for listening voice messages in chats. Currently it is not possible to send them, until the new API will be released.
* For now, all features related to audio playback have been disabled.
* Fixed an error that was making Socializer unable to display chat history properly. It was showing the first 200 items in a conversation instead the last 200 items. Now chat will be displayed accordingly. * Fixed an error that was making Socializer unable to display chat history properly. It was showing the first 200 items in a conversation instead the last 200 items. Now chat will be displayed accordingly.
* Changed the chat history widget from list of items to a read only text box, similar to how it was displayed in skype. Now the widget should be fully visible and messages will work in the same way. * Changed the chat history widget from list of items to a read only text box, similar to how it was displayed in skype. Now the widget should be fully visible and messages will work in the same way.
* It is possible to play songs sent in a chat message by opening them from the attachments panel. * It is possible to play songs sent in a chat message by opening them from the attachments panel.
* Reimplemented most of the audio playback methods.
## Changes in build 2016.07.08 (08/07/2016) ## Changes in build 2016.07.08 (08/07/2016)

View File

@ -13,7 +13,7 @@ import selector
import posts import posts
import attach import attach
from pubsub import pub from pubsub import pub
from vk.exceptions import VkAPIError from vk_api.exceptions import VkApiError
from wxUI.tabs import home from wxUI.tabs import home
from sessionmanager import session, renderers, utils from sessionmanager import session, renderers, utils
from mysc.thread_utils import call_threaded from mysc.thread_utils import call_threaded
@ -78,7 +78,7 @@ class baseBuffer(object):
retrieved = True # Control variable for handling unauthorised/connection errors. retrieved = True # Control variable for handling unauthorised/connection errors.
try: try:
num = getattr(self.session, "get_newsfeed")(show_nextpage=show_nextpage, name=self.name, *self.args, **self.kwargs) num = getattr(self.session, "get_newsfeed")(show_nextpage=show_nextpage, name=self.name, *self.args, **self.kwargs)
except VkAPIError as err: except VkApiError as err:
log.error(u"Error {0}: {1}".format(err.code, err.message)) log.error(u"Error {0}: {1}".format(err.code, err.message))
retrieved = err.code retrieved = err.code
return retrieved return retrieved
@ -311,7 +311,7 @@ class feedBuffer(baseBuffer):
retrieved = True retrieved = True
try: try:
num = getattr(self.session, "get_page")(show_nextpage=show_nextpage, name=self.name, *self.args, **self.kwargs) num = getattr(self.session, "get_page")(show_nextpage=show_nextpage, name=self.name, *self.args, **self.kwargs)
except VkAPIMethodError as err: except ValueError:
log.error(u"Error {0}: {1}".format(err.code, err.message)) log.error(u"Error {0}: {1}".format(err.code, err.message))
retrieved = err.code retrieved = err.code
return retrieved return retrieved
@ -677,7 +677,7 @@ class chatBuffer(baseBuffer):
retrieved = True # Control variable for handling unauthorised/connection errors. retrieved = True # Control variable for handling unauthorised/connection errors.
try: try:
num = getattr(self.session, "get_messages")(name=self.name, *self.args, **self.kwargs) num = getattr(self.session, "get_messages")(name=self.name, *self.args, **self.kwargs)
except VkAPIMethodError as err: except ValueError as err:
log.error(u"Error {0}: {1}".format(err.code, err.message)) log.error(u"Error {0}: {1}".format(err.code, err.message))
retrieved = err.code retrieved = err.code
return retrieved return retrieved
@ -822,7 +822,7 @@ class requestsBuffer(peopleBuffer):
retrieved = True retrieved = True
try: try:
ids = self.session.vk.client.friends.getRequests(*self.args, **self.kwargs) ids = self.session.vk.client.friends.getRequests(*self.args, **self.kwargs)
except VkAPIMethodError as err: except ValueError as err:
log.error(u"Error {0}: {1}".format(err.code, err.message)) log.error(u"Error {0}: {1}".format(err.code, err.message))
retrieved = err.code retrieved = err.code
return retrieved return retrieved

View File

@ -6,7 +6,7 @@ import vkSessionHandler
import sound import sound
from config_utils import Configuration, ConfigurationResetException from config_utils import Configuration, ConfigurationResetException
from pubsub import pub from pubsub import pub
from vk.exceptions import VkAPIError from vk_api.exceptions import LoginRequired, VkApiError
log = logging.getLogger("session") log = logging.getLogger("session")
@ -103,8 +103,7 @@ class vkSession(object):
log.debug("Logged.") log.debug("Logged.")
if result == False: if result == False:
self.authorise() self.authorise()
except VkAPIError as err: except LoginRequired:
if err.code == 5:
self.authorise() self.authorise()
else: else:
self.authorise() self.authorise()
@ -115,7 +114,7 @@ class vkSession(object):
self.vk.login(self.settings["vk"]["user"], self.settings["vk"]["password"]) self.vk.login(self.settings["vk"]["user"], self.settings["vk"]["password"])
self.settings["vk"]["token"] = self.vk.client._session.access_token self.settings["vk"]["token"] = self.vk.client._session.access_token
self.settings.write() self.settings.write()
except: except ValueError:
self.settings["vk"]["user"] = "" self.settings["vk"]["user"] = ""
self.settings["vk"]["password"] = "" self.settings["vk"]["password"] = ""
self.settings.write() self.settings.write()
@ -146,10 +145,19 @@ class vkSession(object):
def get_page(self, name="", show_nextpage=False, endpoint="", *args, **kwargs): def get_page(self, name="", show_nextpage=False, endpoint="", *args, **kwargs):
data = None data = None
if "audio" in endpoint:
c = self.vk.client_audio
else:
c = self.vk.client
if kwargs.has_key("parent_endpoint"): if kwargs.has_key("parent_endpoint"):
p = kwargs["parent_endpoint"] p = kwargs["parent_endpoint"]
if "audio" in p:
c = self.vk.client_audio
kwargs.pop("parent_endpoint") kwargs.pop("parent_endpoint")
p = getattr(self.vk.client, p) try:
p = getattr(c, p)
except AttributeError:
p = c
log.debug("Calling endpoint %s with params %r" % (p, kwargs,)) log.debug("Calling endpoint %s with params %r" % (p, kwargs,))
data = getattr(p, endpoint)(*args, **kwargs) data = getattr(p, endpoint)(*args, **kwargs)
if data != None: if data != None:

View File

@ -1,27 +1,31 @@
#!/usr/bin/python #!/usr/bin/python
import keys import keys
import logging import logging
from vk import API, AuthSession, Session import vk_api
from vk_api.audio import VkAudio
log = logging.getLogger("vkSessionHandler") log = logging.getLogger("vkSessionHandler")
class vkObject(object): class vkObject(object):
def __init__(self): def __init__(self):
self.api_key = keys.keyring.get_api_key() self.api_key = keys.keyring.get_api_key()
self.api_version = 5.84
log.debug("Created vkSession using VK API Version %s" % (self.api_version,))
def login(self, user, password): def login(self, user, password):
log.debug("Logging in vk using user/password authentication") log.debug("Logging in vk using user/password authentication")
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") vk_session = 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.client = API(s, v=self.api_version) vk_session.auth()
self.client = vk_session.get_api()
# self.client = API(s, v=self.api_version)
log.debug("Getting tokens for 24 hours...") log.debug("Getting tokens for 24 hours...")
self.client.account.getProfileInfo() self.client.account.getProfileInfo()
# Add session data to the application statistics. # Add session data to the application statistics.
self.client.stats.trackVisitor() self.client.stats.trackVisitor()
self.client_audio = VkAudio(vk_session)
def login_access_token(self, token): def login_access_token(self, token):
log.debug("Logging in VK using stored tokens...") log.debug("Logging in VK using stored tokens...")
s = Session(access_token=token) vk_session = 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.client = API(s, v=self.api_version) vk_session.auth()
self.client = vk_session.get_api()
self.client_audio = VkAudio(vk_session)
return self.client.account.getProfileInfo() return self.client.account.getProfileInfo()