diff options
author | Bnyro <bnyro@tutanota.com> | 2023-08-05 20:35:04 +0200 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarIT.de> | 2023-08-08 16:21:45 +0200 |
commit | d151497db3ad33efda95b2fc7c1dd0ecf64304b6 (patch) | |
tree | 4dcede4462ad3c7c53b960684f2d0a5209b1d519 /searx | |
parent | cae06f278136cdd10073b431a48969238a7ccbdb (diff) | |
download | searxng-d151497db3ad33efda95b2fc7c1dd0ecf64304b6.tar.gz searxng-d151497db3ad33efda95b2fc7c1dd0ecf64304b6.zip |
[feat] engine: brave - support for news
Diffstat (limited to 'searx')
-rw-r--r-- | searx/engines/brave.py | 28 | ||||
-rw-r--r-- | searx/settings.yml | 10 |
2 files changed, 21 insertions, 17 deletions
diff --git a/searx/engines/brave.py b/searx/engines/brave.py index 61601faf5..deb109b8e 100644 --- a/searx/engines/brave.py +++ b/searx/engines/brave.py @@ -5,7 +5,6 @@ from urllib.parse import urlencode import chompjs -import json about = { "website": 'https://search.brave.com/', @@ -58,12 +57,12 @@ def response(resp): break json_data = chompjs.parse_js_object(datastr) - json_results = json_data[1]["data"]["body"]["response"]["results"] - with open("outfile.json", "w") as f: - json.dump(json_data, f) + json_resp = json_data[1]['data']['body']['response'] + if categories[0] == 'news': + json_resp = json_resp['news'] - for result in json_results: + for result in json_resp["results"]: item = { 'url': result['url'], 'title': result['title'], @@ -72,16 +71,15 @@ def response(resp): if result['thumbnail'] != "null": item['thumbnail'] = result['thumbnail']['src'] - match categories[0]: - case 'images': - item['template'] = 'images.html' - item['img_format'] = result['properties']['format'] - item['source'] = result['source'] - item['img_src'] = result['properties']['url'] - case 'videos': - item['template'] = 'videos.html' - item['length'] = result['video']['duration'] - + if categories[0] == 'images': + item['template'] = 'images.html' + item['img_format'] = result['properties']['format'] + item['source'] = result['source'] + item['img_src'] = result['properties']['url'] + elif categories[0] == 'videos': + item['template'] = 'videos.html' + item['length'] = result['video']['duration'] + results.append(item) return results diff --git a/searx/settings.yml b/searx/settings.yml index a903785e8..87bf381eb 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -1847,13 +1847,19 @@ engines: shortcut: braveimg engine: brave categories: images - disabled: false + disabled: true - name: brave.videos shortcut: bravevid engine: brave categories: videos - disabled: false + disabled: true + + - name: brave.news + shortcut: bravenews + engine: brave + categories: news + disabled: true - name: petalsearch shortcut: pts |