mirror of
https://github.com/searxng/searxng.git
synced 2024-11-26 12:51:02 +00:00
[fix] fdroid engine
This commit is contained in:
parent
fbf6b689dd
commit
fcc9587ee9
2 changed files with 46 additions and 36 deletions
|
@ -18,13 +18,13 @@ categories = ['files']
|
|||
paging = True
|
||||
|
||||
# search-url
|
||||
base_url = 'https://f-droid.org/'
|
||||
search_url = base_url + 'repository/browse/?{query}'
|
||||
base_url = 'https://search.f-droid.org/'
|
||||
search_url = base_url + '?{query}'
|
||||
|
||||
|
||||
# do search-request
|
||||
def request(query, params):
|
||||
query = urlencode({'fdfilter': query, 'fdpage': params['pageno']})
|
||||
query = urlencode({'q': query, 'page': params['pageno'], 'lang': ''})
|
||||
params['url'] = search_url.format(query=query)
|
||||
return params
|
||||
|
||||
|
@ -35,17 +35,16 @@ def response(resp):
|
|||
|
||||
dom = html.fromstring(resp.text)
|
||||
|
||||
for app in dom.xpath('//div[@id="appheader"]'):
|
||||
url = app.xpath('./ancestor::a/@href')[0]
|
||||
title = app.xpath('./p/span/text()')[0]
|
||||
img_src = app.xpath('.//img/@src')[0]
|
||||
for app in dom.xpath('//a[@class="package-header"]'):
|
||||
app_url = app.xpath('./@href')[0]
|
||||
app_title = extract_text(app.xpath('./div/h4[@class="package-name"]/text()'))
|
||||
app_content = extract_text(app.xpath('./div/div/span[@class="package-summary"]')).strip() \
|
||||
+ ' - ' + extract_text(app.xpath('./div/div/span[@class="package-license"]')).strip()
|
||||
app_img_src = app.xpath('./img[@class="package-icon"]/@src')[0]
|
||||
|
||||
content = extract_text(app.xpath('./p')[0])
|
||||
content = content.replace(title, '', 1).strip()
|
||||
|
||||
results.append({'url': url,
|
||||
'title': title,
|
||||
'content': content,
|
||||
'img_src': img_src})
|
||||
results.append({'url': app_url,
|
||||
'title': app_title,
|
||||
'content': app_content,
|
||||
'img_src': app_img_src})
|
||||
|
||||
return results
|
||||
|
|
|
@ -13,29 +13,40 @@ class TestFdroidEngine(SearxTestCase):
|
|||
params = fdroid.request(query, dic)
|
||||
self.assertTrue('url' in params)
|
||||
self.assertTrue(query in params['url'])
|
||||
self.assertTrue('f-droid.org' in params['url'])
|
||||
self.assertTrue('search.f-droid.org' in params['url'])
|
||||
|
||||
def test_response(self):
|
||||
def test_response_empty(self):
|
||||
resp = mock.Mock(text='<html></html>')
|
||||
self.assertEqual(fdroid.response(resp), [])
|
||||
|
||||
def test_response_oneresult(self):
|
||||
html = """
|
||||
<a href="https://google.com/qwerty">
|
||||
<div id="appheader">
|
||||
<div style="float:left;padding-right:10px;">
|
||||
<img src="http://example.com/image.png"
|
||||
style="width:48px;border:none;">
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>test</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="site-wrapper">
|
||||
<div class="main-content">
|
||||
<a class="package-header" href="https://example.com/app.url">
|
||||
<img class="package-icon" src="https://example.com/appexample.logo.png" />
|
||||
|
||||
<div class="package-info">
|
||||
<h4 class="package-name">
|
||||
App Example 1
|
||||
</h4>
|
||||
|
||||
<div class="package-desc">
|
||||
<span class="package-summary">Description App Example 1</span>
|
||||
<span class="package-license">GPL-3.0-only</span>
|
||||
</div>
|
||||
<div style="float:right;">
|
||||
<p>Details...</p>
|
||||
</div>
|
||||
<p style="color:#000000;">
|
||||
<span style="font-size:20px;">Sample title</span>
|
||||
<br>
|
||||
Sample content
|
||||
</p>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
resp = mock.Mock(text=html)
|
||||
|
@ -43,7 +54,7 @@ class TestFdroidEngine(SearxTestCase):
|
|||
|
||||
self.assertEqual(type(results), list)
|
||||
self.assertEqual(len(results), 1)
|
||||
self.assertEqual(results[0]['url'], 'https://google.com/qwerty')
|
||||
self.assertEqual(results[0]['title'], 'Sample title')
|
||||
self.assertEqual(results[0]['content'], 'Sample content')
|
||||
self.assertEqual(results[0]['img_src'], 'http://example.com/image.png')
|
||||
self.assertEqual(results[0]['url'], 'https://example.com/app.url')
|
||||
self.assertEqual(results[0]['title'], 'App Example 1')
|
||||
self.assertEqual(results[0]['content'], 'Description App Example 1 - GPL-3.0-only')
|
||||
self.assertEqual(results[0]['img_src'], 'https://example.com/appexample.logo.png')
|
||||
|
|
Loading…
Reference in a new issue