@@ -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']
@@ -27,7 +28,8 @@ search_url = base_url+'search?'
27results_xpath = '//li[@data-item-type="tweet"]'
28results_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()'
30−content_xpath = './/p[@class="js-tweet-text tweet-text"]//text()'
31+content_xpath = './/p[@class="js-tweet-text tweet-text"]'
32+timestamp_xpath = './/span[contains(@class,"_timestamp")]'
33# do search-request
35# do search-request
@@ -52,12 +54,21 @@ def response(resp):
52 link = tweet.xpath(link_xpath)[0]
54 link = tweet.xpath(link_xpath)[0]
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(html.tostring(tweet.xpath(content_xpath)[0], method='text', encoding='UTF-8').decode("utf-8"))
56−
58+ pubdate = tweet.xpath(timestamp_xpath)
60+ timestamp = float(pubdate[0].attrib.get('data-time'))
61+ publishedDate = datetime.fromtimestamp(timestamp, None)
57− # append result
62+ # append result
63+ results.append({'url': url,
66+ 'publishedDate': publishedDate})
58− results.append({'url': url,
69+ results.append({'url': url,
59− 'title': title,
70+ 'title': title,
60− 'content': content})
71+ 'content': content})
62 # return results
73 # return results
63 return results
74 return results