Replaced VK with vk_api
This commit is contained in:
parent
1a79e7149c
commit
bb26d45f1d
@ -10,10 +10,10 @@
|
||||
* 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 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.
|
||||
* 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.
|
||||
* Reimplemented most of the audio playback methods.
|
||||
|
||||
## Changes in build 2016.07.08 (08/07/2016)
|
||||
|
||||
|
@ -13,7 +13,7 @@ import selector
|
||||
import posts
|
||||
import attach
|
||||
from pubsub import pub
|
||||
from vk.exceptions import VkAPIError
|
||||
from vk_api.exceptions import VkApiError
|
||||
from wxUI.tabs import home
|
||||
from sessionmanager import session, renderers, utils
|
||||
from mysc.thread_utils import call_threaded
|
||||
@ -78,7 +78,7 @@ class baseBuffer(object):
|
||||
retrieved = True # Control variable for handling unauthorised/connection errors.
|
||||
try:
|
||||
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))
|
||||
retrieved = err.code
|
||||
return retrieved
|
||||
@ -311,7 +311,7 @@ class feedBuffer(baseBuffer):
|
||||
retrieved = True
|
||||
try:
|
||||
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))
|
||||
retrieved = err.code
|
||||
return retrieved
|
||||
@ -677,7 +677,7 @@ class chatBuffer(baseBuffer):
|
||||
retrieved = True # Control variable for handling unauthorised/connection errors.
|
||||
try:
|
||||
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))
|
||||
retrieved = err.code
|
||||
return retrieved
|
||||
@ -822,7 +822,7 @@ class requestsBuffer(peopleBuffer):
|
||||
retrieved = True
|
||||
try:
|
||||
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))
|
||||
retrieved = err.code
|
||||
return retrieved
|
||||
|
@ -6,7 +6,7 @@ import vkSessionHandler
|
||||
import sound
|
||||
from config_utils import Configuration, ConfigurationResetException
|
||||
from pubsub import pub
|
||||
from vk.exceptions import VkAPIError
|
||||
from vk_api.exceptions import LoginRequired, VkApiError
|
||||
|
||||
log = logging.getLogger("session")
|
||||
|
||||
@ -103,9 +103,8 @@ class vkSession(object):
|
||||
log.debug("Logged.")
|
||||
if result == False:
|
||||
self.authorise()
|
||||
except VkAPIError as err:
|
||||
if err.code == 5:
|
||||
self.authorise()
|
||||
except LoginRequired:
|
||||
self.authorise()
|
||||
else:
|
||||
self.authorise()
|
||||
self.get_my_data()
|
||||
@ -115,7 +114,7 @@ class vkSession(object):
|
||||
self.vk.login(self.settings["vk"]["user"], self.settings["vk"]["password"])
|
||||
self.settings["vk"]["token"] = self.vk.client._session.access_token
|
||||
self.settings.write()
|
||||
except:
|
||||
except ValueError:
|
||||
self.settings["vk"]["user"] = ""
|
||||
self.settings["vk"]["password"] = ""
|
||||
self.settings.write()
|
||||
@ -146,10 +145,19 @@ class vkSession(object):
|
||||
|
||||
def get_page(self, name="", show_nextpage=False, endpoint="", *args, **kwargs):
|
||||
data = None
|
||||
if "audio" in endpoint:
|
||||
c = self.vk.client_audio
|
||||
else:
|
||||
c = self.vk.client
|
||||
if kwargs.has_key("parent_endpoint"):
|
||||
p = kwargs["parent_endpoint"]
|
||||
if "audio" in p:
|
||||
c = self.vk.client_audio
|
||||
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,))
|
||||
data = getattr(p, endpoint)(*args, **kwargs)
|
||||
if data != None:
|
||||
|
@ -1,27 +1,31 @@
|
||||
#!/usr/bin/python
|
||||
import keys
|
||||
import logging
|
||||
from vk import API, AuthSession, Session
|
||||
import vk_api
|
||||
from vk_api.audio import VkAudio
|
||||
log = logging.getLogger("vkSessionHandler")
|
||||
|
||||
class vkObject(object):
|
||||
|
||||
def __init__(self):
|
||||
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):
|
||||
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")
|
||||
self.client = API(s, v=self.api_version)
|
||||
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")
|
||||
vk_session.auth()
|
||||
self.client = vk_session.get_api()
|
||||
# self.client = API(s, v=self.api_version)
|
||||
log.debug("Getting tokens for 24 hours...")
|
||||
self.client.account.getProfileInfo()
|
||||
# Add session data to the application statistics.
|
||||
self.client.stats.trackVisitor()
|
||||
self.client_audio = VkAudio(vk_session)
|
||||
|
||||
def login_access_token(self, token):
|
||||
log.debug("Logging in VK using stored tokens...")
|
||||
s = Session(access_token=token)
|
||||
self.client = API(s, v=self.api_version)
|
||||
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")
|
||||
vk_session.auth()
|
||||
self.client = vk_session.get_api()
|
||||
self.client_audio = VkAudio(vk_session)
|
||||
return self.client.account.getProfileInfo()
|
Loading…
Reference in New Issue
Block a user