[twitter] allow to unofficially follow users

This commit is contained in:
Bezleputh 2014-05-22 15:16:28 +02:00
commit 1afbb241da
2 changed files with 14 additions and 11 deletions

View file

@ -22,7 +22,7 @@ from datetime import time, datetime, timedelta
from weboob.tools.value import Value, ValueBackendPassword
from weboob.tools.backend import BaseBackend, BackendConfig
from weboob.capabilities.messages import ICapMessages, Thread, ICapMessagesPost
from weboob.capabilities.collection import ICapCollection, CollectionNotFound
from weboob.capabilities.collection import ICapCollection, CollectionNotFound, Collection
from weboob.capabilities.base import find_object
from weboob.tools.exceptions import BrowserForbidden
from .browser import TwitterBrowser
@ -42,7 +42,8 @@ class TwitterBackend(BaseBackend, ICapMessages, ICapMessagesPost, ICapCollection
STORAGE = {'seen': {}}
CONFIG = BackendConfig(Value('username', label='Username', default=''),
ValueBackendPassword('password', label='Password', default=''))
ValueBackendPassword('password', label='Password', default=''),
Value('profils_subscribe', label='Profils subscribe', default=''))
def create_default_browser(self):
return self.create_browser(self.config['username'].get(), self.config['password'].get())
@ -100,9 +101,17 @@ class TwitterBackend(BaseBackend, ICapMessages, ICapMessagesPost, ICapCollection
def iter_resources(self, objs, split_path):
collection = self.get_collection(objs, split_path)
if collection.path_level == 0:
return self.browser.get_collections()
if self.config['username']:
me = self.browser.get_me()
yield Collection([me], me)
profils = self.config['profils_subscribe'].get()
if profils:
for profil in profils.split(','):
yield Collection([profil], profil)
if collection.path_level == 1:
return self.browser.get_tweets_from_collection(collection.split_path[0])
for el in self.browser.get_tweets_from_collection(collection.split_path[0]):
yield el
def validate_collection(self, objs, collection):
if collection.path_level == 0:

View file

@ -20,7 +20,6 @@
from weboob.tools.browser2 import LoginBrowser, URL, need_login
from weboob.tools.browser import BrowserIncorrectPassword
from weboob.capabilities.messages import Message
from weboob.capabilities.collection import Collection
from .pages import LoginPage, LoginErrorPage, ThreadPage, TwitterBasePage, Tweet
@ -33,7 +32,7 @@ class TwitterBrowser(LoginBrowser):
thread_page = URL(u'(?P<user>.+)/status/(?P<_id>.+)', ThreadPage)
login_error = URL(u'login/error.+', LoginErrorPage)
tweet = URL(u'i/tweet/create', Tweet)
twitter_page = URL(u'(?P<path>.+)', TwitterBasePage)
twitter_page = URL(u'(?P<path>.+)/with_replies', TwitterBasePage)
login = URL(u'', LoginPage)
def do_login(self):
@ -97,10 +96,5 @@ class TwitterBrowser(LoginBrowser):
return thread
def get_collections(self):
if self.username:
me = self.get_me()
yield Collection([me], me)
def get_tweets_from_collection(self, path):
return self.twitter_page.go(path=path).iter_threads()