summaryrefslogtreecommitdiff
path: root/searx/engines/twitter.py
diff options
context:
space:
mode:
authorasciimoo <asciimoo@gmail.com>2013-10-20 10:40:02 +0200
committerasciimoo <asciimoo@gmail.com>2013-10-20 10:40:02 +0200
commitc7b5cddc485768f47a75b2432a5aebd0130f676c (patch)
tree891e84392e8c84b324dc12dcb26884757b8c773f /searx/engines/twitter.py
parent0cfc4b4c8ae0197c8def545b7576448d2b11a928 (diff)
downloadsearxng-c7b5cddc485768f47a75b2432a5aebd0130f676c.tar.gz
searxng-c7b5cddc485768f47a75b2432a5aebd0130f676c.zip
[enh] twitter engine added
Diffstat (limited to 'searx/engines/twitter.py')
-rw-r--r--searx/engines/twitter.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/searx/engines/twitter.py b/searx/engines/twitter.py
new file mode 100644
index 000000000..d0a0aef17
--- /dev/null
+++ b/searx/engines/twitter.py
@@ -0,0 +1,26 @@
+from urlparse import urljoin
+from urllib import urlencode
+from lxml import html
+
+categories = ['social media']
+
+base_url = 'https://twitter.com/'
+search_url = base_url+'search?'
+
+def request(query, params):
+ global search_url
+ params['url'] = search_url + urlencode({'q': query})
+ return params
+
+
+def response(resp):
+ global base_url
+ results = []
+ dom = html.fromstring(resp.text)
+ for tweet in dom.xpath('//li[@data-item-type="tweet"]'):
+ link = tweet.xpath('.//small[@class="time"]//a')[0]
+ url = urljoin(base_url, link.attrib.get('href'))
+ title = ''.join(tweet.xpath('.//span[@class="username js-action-profile-name"]//text()'))
+ content = ''.join(map(html.tostring, tweet.xpath('.//p[@class="js-tweet-text tweet-text"]//*')))
+ results.append({'url': url, 'title': title, 'content': content})
+ return results