Ejemplo n.º 1
0
    def __init__(self,
                 username,
                 account_id,
                 protocol_id,
                 password,
                 auth,
                 config=None):
        self.id_ = account_id  # username-protocol_id
        self.username = username
        self.protocol_id = protocol_id

        if protocol_id == ProtocolType.TWITTER:
            self.protocol = twitter.Main(username, self.id_, auth)
        elif protocol_id == ProtocolType.IDENTICA:
            self.protocol = identica.Main(username, self.id_, auth)

        self.profile = Profile()
        self.profile.username = username
        self.profile.password = password
        self.friends = None
        self.columns = []
        self.lists = None
        self.token = None
        self.logged_in = LoginStatus.NONE
        if config:
            self.config = config
        else:
            self.config = AccountConfig(account_id, password)
Ejemplo n.º 2
0
 def change_id(self, original_id, destination_id):
     account = self.get(original_id)
     new_id = "%s-%s" % (destination_id, account.protocol_id)
     self.unregister(original_id, True)
     account.username = destination_id
     account.profile.username = destination_id
     account.config = AccountConfig(new_id, "")
     account.store_token()
     account.id_ = new_id
     self.__accounts[new_id] = account
     return new_id
Ejemplo n.º 3
0
    def save(self):
        """
        Save to disk the configuration and credentials for the account. If the
        account hasn't been authenticated it will raise an
        :class:`libturpial.exceptions.AccountNotAuthenticated` exception.
        """
        if not self.is_authenticated():
            raise AccountNotAuthenticated

        self.config = AccountConfig(self.id_)
        token = self.get_oauth_token()
        if token:
            self.config.save_oauth_credentials(token.key, token.secret)
Ejemplo n.º 4
0
    def load(self, account_id):
        cfg = AccountConfig(account_id)
        auth = cfg.read_section('OAuth')
        username = cfg.read('Login', 'username')
        protocol = cfg.read('Login', 'protocol')
        p = cfg.revert(cfg.read('Login', 'password'), username)

        if self.__accounts.has_key(account_id):
            self.log.debug('Account %s is already registered' % account_id)
        else:
            account = Account(username, account_id, protocol, p, auth, cfg)
            timeout = int(self.config.read('Advanced', 'socket-timeout'))
            account.protocol.timeout = timeout
            self.log.debug('Using %i sec for socket timeout in account %s' %
                           (account.protocol.timeout, account_id))
            self.__accounts[account_id] = account
            self.log.debug('Account %s loaded successfully' % account_id)
        return account_id
Ejemplo n.º 5
0
    def load(account_id):
        """
        Return the account object associated to *account_id* loaded from
        existing configuration. If the *account_id* does not correspond to a
        valid account it returns a
        :class:`libturpial.exceptions.ErrorLoadingAccount` exception.

        If credentials in configuration file are empty it returns a
        :class:`libturpial.exceptions.EmptyOAuthCredentials` exception.
        """
        if not AccountConfig.exists(account_id):
            raise ErrorLoadingAccount("Account has no stored credentials")

        username = get_username_from(account_id)
        protocol_id = get_protocol_from(account_id)

        account = Account.new(protocol_id, username)
        account.config = AccountConfig(account_id)
        key, secret = account.config.load_oauth_credentials()
        account.setup_user_credentials(account.id_, key, secret)
        account.fetch()
        return account