|
@@ -0,0 +1,66 @@
|
|
1
|
+## Digg (News, Social media)
|
|
2
|
+#
|
|
3
|
+# @website https://digg.com/
|
|
4
|
+# @provide-api no
|
|
5
|
+#
|
|
6
|
+# @using-api no
|
|
7
|
+# @results HTML (using search portal)
|
|
8
|
+# @stable no (HTML can change)
|
|
9
|
+# @parse url, title, content, publishedDate, thumbnail
|
|
10
|
+
|
|
11
|
+from urllib import quote_plus
|
|
12
|
+from json import loads
|
|
13
|
+from lxml import html
|
|
14
|
+from cgi import escape
|
|
15
|
+from dateutil import parser
|
|
16
|
+
|
|
17
|
+# engine dependent config
|
|
18
|
+categories = ['news', 'social media']
|
|
19
|
+paging = True
|
|
20
|
+
|
|
21
|
+# search-url
|
|
22
|
+base_url = 'https://digg.com/'
|
|
23
|
+search_url = base_url+'api/search/{query}.json?position={position}&format=html'
|
|
24
|
+
|
|
25
|
+# specific xpath variables
|
|
26
|
+results_xpath = '//article'
|
|
27
|
+link_xpath = './/small[@class="time"]//a'
|
|
28
|
+title_xpath = './/h2//a//text()'
|
|
29
|
+content_xpath = './/p//text()'
|
|
30
|
+pubdate_xpath = './/time'
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+# do search-request
|
|
34
|
+def request(query, params):
|
|
35
|
+ offset = (params['pageno'] - 1) * 10
|
|
36
|
+ params['url'] = search_url.format(position=offset,
|
|
37
|
+ query=quote_plus(query))
|
|
38
|
+ return params
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+# get response from search-request
|
|
42
|
+def response(resp):
|
|
43
|
+ results = []
|
|
44
|
+
|
|
45
|
+ search_result = loads(resp.text)
|
|
46
|
+
|
|
47
|
+ dom = html.fromstring(search_result['html'])
|
|
48
|
+
|
|
49
|
+ # parse results
|
|
50
|
+ for result in dom.xpath(results_xpath):
|
|
51
|
+ url = result.attrib.get('data-contenturl')
|
|
52
|
+ thumbnail = result.xpath('.//img')[0].attrib.get('src')
|
|
53
|
+ title = ''.join(result.xpath(title_xpath))
|
|
54
|
+ content = escape(''.join(result.xpath(content_xpath)))
|
|
55
|
+ publishedDate = parser.parse(result.xpath(pubdate_xpath)[0].attrib.get('datetime'))
|
|
56
|
+
|
|
57
|
+ # append result
|
|
58
|
+ results.append({'url': url,
|
|
59
|
+ 'title': title,
|
|
60
|
+ 'content': content,
|
|
61
|
+ 'template': 'videos.html',
|
|
62
|
+ 'publishedDate': publishedDate,
|
|
63
|
+ 'thumbnail': thumbnail})
|
|
64
|
+
|
|
65
|
+ # return results
|
|
66
|
+ return results
|