|
@@ -1,6 +1,6 @@
|
|
|
|
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -14,6 +14,7 @@ from urlparse import urljoin
|
|
from urllib import urlencode
|
|
from urllib import urlencode
|
|
from lxml import html
|
|
from lxml import html
|
|
from cgi import escape
|
|
from cgi import escape
|
|
|
|
+from datetime import datetime
|
|
|
|
|
|
|
|
|
|
categories = ['social media']
|
|
categories = ['social media']
|
|
@@ -27,7 +28,8 @@ search_url = base_url+'search?'
|
|
results_xpath = '//li[@data-item-type="tweet"]'
|
|
results_xpath = '//li[@data-item-type="tweet"]'
|
|
link_xpath = './/small[@class="time"]//a'
|
|
link_xpath = './/small[@class="time"]//a'
|
|
title_xpath = './/span[@class="username js-action-profile-name"]//text()'
|
|
title_xpath = './/span[@class="username js-action-profile-name"]//text()'
|
|
-content_xpath = './/p[@class="js-tweet-text tweet-text"]//text()'
|
|
+content_xpath = './/p[@class="js-tweet-text tweet-text"]'
|
|
|
|
+timestamp_xpath = './/span[contains(@class,"_timestamp")]'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -52,12 +54,21 @@ def response(resp):
|
|
link = tweet.xpath(link_xpath)[0]
|
|
link = tweet.xpath(link_xpath)[0]
|
|
url = urljoin(base_url, link.attrib.get('href'))
|
|
url = urljoin(base_url, link.attrib.get('href'))
|
|
title = ''.join(tweet.xpath(title_xpath))
|
|
title = ''.join(tweet.xpath(title_xpath))
|
|
- content = escape(''.join(tweet.xpath(content_xpath)))
|
|
+ content = escape(html.tostring(tweet.xpath(content_xpath)[0], method='text', encoding='UTF-8').decode("utf-8"))
|
|
-
|
|
+ pubdate = tweet.xpath(timestamp_xpath)
|
|
-
|
|
+ if len(pubdate) > 0:
|
|
- results.append({'url': url,
|
|
+ timestamp = float(pubdate[0].attrib.get('data-time'))
|
|
- 'title': title,
|
|
+ publishedDate = datetime.fromtimestamp(timestamp, None)
|
|
- 'content': content})
|
|
+
|
|
|
|
+ results.append({'url': url,
|
|
|
|
+ 'title': title,
|
|
|
|
+ 'content': content,
|
|
|
|
+ 'publishedDate': publishedDate})
|
|
|
|
+ else:
|
|
|
|
+
|
|
|
|
+ results.append({'url': url,
|
|
|
|
+ 'title': title,
|
|
|
|
+ 'content': content})
|
|
|
|
|
|
|
|
|
|
return results
|
|
return results
|