[twitter] follow timelines while hastags querying

This commit is contained in:
Bezleputh 2014-06-03 01:07:17 +02:00
commit d5ef80ead3
2 changed files with 5 additions and 23 deletions

View file

@ -20,7 +20,7 @@
from weboob.tools.browser2 import LoginBrowser, URL, need_login
from weboob.tools.browser import BrowserIncorrectPassword
from weboob.capabilities.messages import Message
from .pages import LoginPage, LoginErrorPage, ThreadPage, TwitterBasePage, Tweet, TrendsPage,\
from .pages import LoginPage, LoginErrorPage, ThreadPage, Tweet, TrendsPage,\
TimelinePage, HomeTimelinePage, SearchTimelinePage
@ -34,7 +34,6 @@ class TwitterBrowser(LoginBrowser):
login_error = URL(u'login/error.+', LoginErrorPage)
tweet = URL(u'i/tweet/create', Tweet)
trends = URL(u'trends', TrendsPage)
hashtag = URL(u'hashtag/(?P<path>.+)\?f=realtime', TwitterBasePage)
search = URL(u'i/search/timeline', SearchTimelinePage)
profil = URL(u'i/profiles/show/(?P<path>.+)/timeline/with_replies', HomeTimelinePage)
timeline = URL(u'i/timeline', TimelinePage)
@ -115,7 +114,7 @@ class TwitterBrowser(LoginBrowser):
return self.profil.go(path=path).iter_threads()
def get_tweets_from_hashtag(self, path):
return self.hashtag.go(path=path.lstrip('#')).iter_threads()
return self.get_tweets_from_search(u'#%s' % path if not path.startswith('#') else path)
def get_tweets_from_search(self, path):
params = {'q': "%s" % path,

View file

@ -27,7 +27,7 @@ from weboob.tools.browser2.page import HTMLPage, JsonPage, method, ListElement,
from weboob.tools.browser2.filters import CleanText, Format, Link, Regexp, Env, DateTime, Attr, Filter
from weboob.capabilities.messages import Thread, Message
from weboob.capabilities.base import CapBaseObject
__all__ = ['LoginPage', 'LoginErrorPage', 'ThreadPage', 'TwitterBasePage', 'Tweet', 'TrendsPage', 'TimelinePage', 'HomeTimelinePage', 'SearchTimelinePage']
__all__ = ['LoginPage', 'LoginErrorPage', 'ThreadPage', 'Tweet', 'TrendsPage', 'TimelinePage', 'HomeTimelinePage', 'SearchTimelinePage']
class DatetimeFromTimestamp(Filter):
@ -55,24 +55,7 @@ class TwitterJsonHTMLPage(JsonPage):
self.doc = html.parse(StringIO(self.doc['items_html']), parser)
class TwitterBasePage(HTMLPage):
@method
class iter_threads(ListElement):
item_xpath = '//*[@data-item-type="tweet"]/div'
class item(ItemElement):
klass = Thread
obj_id = Regexp(Link('./div/div/a[@class="details with-icn js-details"]|./div/div/span/a[@class="ProfileTweet-timestamp js-permalink js-nav js-tooltip"]'), '/(.+)/status/(.+)', '\\1#\\2')
obj_title = Format('%s \n\t %s',
CleanText('./div/div[@class="stream-item-header"]/a|./div/div[@class="ProfileTweet-authorDetails"]/a',
replace=[('@ ', '@'), ('# ', '#'), ('http:// ', 'http://')]),
CleanText('./div/p',
replace=[('@ ', '@'), ('# ', '#'), ('http:// ', 'http://')]))
obj_date = DatetimeFromTimestamp(Attr('./div/div[@class="stream-item-header"]/small/a/span|./div/div/span/a[@class="ProfileTweet-timestamp js-permalink js-nav js-tooltip"]/span', 'data-time'))
class LoginPage(TwitterBasePage):
class LoginPage(HTMLPage):
def login(self, login, passwd):
form = self.get_form(xpath='//form[@action="https://twitter.com/sessions"]')
form['session[username_or_email]'] = login