import utils
import vk_api

class VK(utils.Verbose):
    def __init__(self, conf = None):
        if not conf:
            self.config = utils.Config()
        else:
            self.config = conf

        self.login    = self.config.get('vk', 'login')
        self.password = self.config.get('vk', 'password')
        self.number   = self.config.get('vk', 'number')

        # vk_api requirement
        if (self.login == self.number):
            self.number = None

        self.session  = vk_api.VkApi(login = self.login, password = self.password, number = self.number)

        try:
            self.debug('authorization')
            self.session.authorization()
        except vk_api.AuthorizationError as error_msg:
            self.debug(error_msg)
            return

    def api(self):
        return self.session.get_api()
