2015-05-02 13:45:17 +00:00
|
|
|
"""
|
|
|
|
Deviantart (Images)
|
|
|
|
|
|
|
|
@website https://www.deviantart.com/
|
|
|
|
@provide-api yes (https://www.deviantart.com/developers/) (RSS)
|
|
|
|
|
|
|
|
@using-api no (TODO, rewrite to api)
|
|
|
|
@results HTML
|
|
|
|
@stable no (HTML can change)
|
2020-11-03 07:44:41 +00:00
|
|
|
@parse url, title, img_src
|
2015-05-02 13:45:17 +00:00
|
|
|
|
|
|
|
@todo rewrite to api
|
|
|
|
"""
|
2020-11-03 07:44:41 +00:00
|
|
|
# pylint: disable=missing-function-docstring
|
2014-09-02 14:48:18 +00:00
|
|
|
|
2020-08-06 15:42:46 +00:00
|
|
|
from urllib.parse import urlencode
|
2020-11-03 07:44:41 +00:00
|
|
|
from lxml import html
|
2013-10-20 09:12:10 +00:00
|
|
|
|
2014-09-02 14:48:18 +00:00
|
|
|
# engine dependent config
|
2013-10-20 09:12:10 +00:00
|
|
|
categories = ['images']
|
2014-09-02 14:48:18 +00:00
|
|
|
paging = True
|
2016-07-19 08:06:47 +00:00
|
|
|
time_range_support = True
|
2013-10-20 09:12:10 +00:00
|
|
|
|
2020-11-03 07:44:41 +00:00
|
|
|
time_range_dict = {
|
|
|
|
'day': 'popular-24-hours',
|
|
|
|
'week': 'popular-1-week',
|
|
|
|
'month': 'popular-1-month',
|
|
|
|
'year': 'most-recent',
|
|
|
|
}
|
2014-01-29 23:09:47 +00:00
|
|
|
|
2020-11-03 07:44:41 +00:00
|
|
|
# search-url
|
|
|
|
base_url = 'https://www.deviantart.com'
|
2014-01-20 01:31:20 +00:00
|
|
|
|
2013-10-20 09:12:10 +00:00
|
|
|
def request(query, params):
|
2016-12-11 15:41:14 +00:00
|
|
|
|
2020-11-03 07:44:41 +00:00
|
|
|
# https://www.deviantart.com/search/deviations?page=5&q=foo
|
|
|
|
|
|
|
|
query = {
|
|
|
|
'page' : params['pageno'],
|
|
|
|
'q' : query,
|
|
|
|
}
|
2016-07-25 22:22:05 +00:00
|
|
|
if params['time_range'] in time_range_dict:
|
2020-11-03 07:44:41 +00:00
|
|
|
query['order'] = time_range_dict[params['time_range']]
|
2014-09-02 14:48:18 +00:00
|
|
|
|
2020-11-03 07:44:41 +00:00
|
|
|
params['url'] = base_url + '/search/deviations?' + urlencode(query)
|
2013-10-20 09:12:10 +00:00
|
|
|
|
2020-11-03 07:44:41 +00:00
|
|
|
return params
|
2013-10-20 09:12:10 +00:00
|
|
|
|
|
|
|
def response(resp):
|
2014-09-02 14:48:18 +00:00
|
|
|
|
2020-11-03 07:44:41 +00:00
|
|
|
results = []
|
2014-09-02 14:48:18 +00:00
|
|
|
|
2013-10-20 09:12:10 +00:00
|
|
|
dom = html.fromstring(resp.text)
|
2015-01-17 18:24:35 +00:00
|
|
|
|
2019-10-16 12:42:31 +00:00
|
|
|
for row in dom.xpath('//div[contains(@data-hook, "content_row")]'):
|
|
|
|
for result in row.xpath('./div'):
|
2020-11-03 07:44:41 +00:00
|
|
|
|
|
|
|
a_tag = result.xpath('.//a[@data-hook="deviation_link"]')[0]
|
|
|
|
noscript_tag = a_tag.xpath('.//noscript')
|
|
|
|
|
|
|
|
if noscript_tag:
|
|
|
|
img_tag = noscript_tag[0].xpath('.//img')
|
|
|
|
else:
|
|
|
|
img_tag = a_tag.xpath('.//img')
|
|
|
|
if not img_tag:
|
|
|
|
continue
|
|
|
|
img_tag = img_tag[0]
|
|
|
|
|
|
|
|
results.append({
|
|
|
|
'template': 'images.html',
|
|
|
|
'url': a_tag.attrib.get('href'),
|
|
|
|
'img_src': img_tag.attrib.get('src'),
|
|
|
|
'title': img_tag.attrib.get('alt'),
|
|
|
|
})
|
|
|
|
|
2013-10-20 09:12:10 +00:00
|
|
|
return results
|