@@ -1,6 +1,6 @@
1## Twitter (Social media)
1## Twitter (Social media)
3−# @website https://www.bing.com/news
3+# @website https://twitter.com/
4# @provide-api yes (https://dev.twitter.com/docs/using-search)
4# @provide-api yes (https://dev.twitter.com/docs/using-search)
6# @using-api no
6# @using-api no
@@ -14,6 +14,7 @@ from urlparse import urljoin
14from urllib import urlencode
14from urllib import urlencode
15from lxml import html
15from lxml import html
16from cgi import escape
16from cgi import escape
17+from datetime import datetime
18# engine dependent config
19# engine dependent config
19categories = ['social media']
20categories = ['social media']
@@ -28,6 +29,7 @@ results_xpath = '//li[@data-item-type="tweet"]'
28link_xpath = './/small[@class="time"]//a'
29link_xpath = './/small[@class="time"]//a'
29title_xpath = './/span[@class="username js-action-profile-name"]//text()'
30title_xpath = './/span[@class="username js-action-profile-name"]//text()'
30content_xpath = './/p[@class="js-tweet-text tweet-text"]//text()'
31content_xpath = './/p[@class="js-tweet-text tweet-text"]//text()'
32+timestamp_xpath = './/span[contains(@class,"_timestamp")]'
33# do search-request
35# do search-request
@@ -53,11 +55,19 @@ def response(resp):
53 url = urljoin(base_url, link.attrib.get('href'))
55 url = urljoin(base_url, link.attrib.get('href'))
54 title = ''.join(tweet.xpath(title_xpath))
56 title = ''.join(tweet.xpath(title_xpath))
55 content = escape(''.join(tweet.xpath(content_xpath)))
57 content = escape(''.join(tweet.xpath(content_xpath)))
56−
58+ pubdate = tweet.xpath(timestamp_xpath)
60+ publishedDate = datetime.fromtimestamp(float(pubdate[0].attrib.get('data-time')), None)
57− # append result
61+ # append result
62+ results.append({'url': url,
65+ 'publishedDate': publishedDate})
58− results.append({'url': url,
68+ results.append({'url': url,
59− 'title': title,
69+ 'title': title,
60− 'content': content})
70+ 'content': content})
62 # return results
72 # return results
63 return results
73 return results