diff options
author | Cqoicebordel <Cqoicebordel@users.noreply.github.com> | 2014-12-28 22:57:59 +0100 |
---|---|---|
committer | Cqoicebordel <Cqoicebordel@users.noreply.github.com> | 2014-12-28 22:57:59 +0100 |
commit | e7e298153678fc0e77e24a3ae3b333b1230136b2 (patch) | |
tree | c338bb441cf5572fe72cbb4e3efc6be2a0f5babe /searx/engines/twitter.py | |
parent | 011c43b485ed66d399aede2ca1366805496ab8b8 (diff) | |
download | searxng-e7e298153678fc0e77e24a3ae3b333b1230136b2.tar.gz searxng-e7e298153678fc0e77e24a3ae3b333b1230136b2.zip |
Digg + Twitter corrections
Digg engines, with thumbnails
Add pubdate for twitter
Diffstat (limited to 'searx/engines/twitter.py')
-rw-r--r-- | searx/engines/twitter.py | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/searx/engines/twitter.py b/searx/engines/twitter.py index 0689150c8..5a7046c83 100644 --- a/searx/engines/twitter.py +++ b/searx/engines/twitter.py @@ -1,6 +1,6 @@ ## Twitter (Social media) # -# @website https://www.bing.com/news +# @website https://twitter.com/ # @provide-api yes (https://dev.twitter.com/docs/using-search) # # @using-api no @@ -14,6 +14,7 @@ from urlparse import urljoin from urllib import urlencode from lxml import html from cgi import escape +from datetime import datetime # engine dependent config categories = ['social media'] @@ -28,6 +29,7 @@ results_xpath = '//li[@data-item-type="tweet"]' link_xpath = './/small[@class="time"]//a' title_xpath = './/span[@class="username js-action-profile-name"]//text()' content_xpath = './/p[@class="js-tweet-text tweet-text"]//text()' +timestamp_xpath = './/span[contains(@class,"_timestamp")]' # do search-request @@ -53,11 +55,19 @@ def response(resp): url = urljoin(base_url, link.attrib.get('href')) title = ''.join(tweet.xpath(title_xpath)) content = escape(''.join(tweet.xpath(content_xpath))) - - # append result - results.append({'url': url, - 'title': title, - 'content': content}) + pubdate = tweet.xpath(timestamp_xpath) + if len(pubdate) > 0: + publishedDate = datetime.fromtimestamp(float(pubdate[0].attrib.get('data-time')), None) + # append result + results.append({'url': url, + 'title': title, + 'content': content, + 'publishedDate': publishedDate}) + else: + # append result + results.append({'url': url, + 'title': title, + 'content': content}) # return results return results |