forked from Ponysearch/Ponysearch
[feat] engine: brave - support for news
This commit is contained in:
parent
cae06f2781
commit
d151497db3
2 changed files with 21 additions and 17 deletions
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
import chompjs
|
import chompjs
|
||||||
import json
|
|
||||||
|
|
||||||
about = {
|
about = {
|
||||||
"website": 'https://search.brave.com/',
|
"website": 'https://search.brave.com/',
|
||||||
|
@ -58,12 +57,12 @@ def response(resp):
|
||||||
break
|
break
|
||||||
|
|
||||||
json_data = chompjs.parse_js_object(datastr)
|
json_data = chompjs.parse_js_object(datastr)
|
||||||
json_results = json_data[1]["data"]["body"]["response"]["results"]
|
|
||||||
|
|
||||||
with open("outfile.json", "w") as f:
|
json_resp = json_data[1]['data']['body']['response']
|
||||||
json.dump(json_data, f)
|
if categories[0] == 'news':
|
||||||
|
json_resp = json_resp['news']
|
||||||
|
|
||||||
for result in json_results:
|
for result in json_resp["results"]:
|
||||||
item = {
|
item = {
|
||||||
'url': result['url'],
|
'url': result['url'],
|
||||||
'title': result['title'],
|
'title': result['title'],
|
||||||
|
@ -72,16 +71,15 @@ def response(resp):
|
||||||
if result['thumbnail'] != "null":
|
if result['thumbnail'] != "null":
|
||||||
item['thumbnail'] = result['thumbnail']['src']
|
item['thumbnail'] = result['thumbnail']['src']
|
||||||
|
|
||||||
match categories[0]:
|
if categories[0] == 'images':
|
||||||
case 'images':
|
item['template'] = 'images.html'
|
||||||
item['template'] = 'images.html'
|
item['img_format'] = result['properties']['format']
|
||||||
item['img_format'] = result['properties']['format']
|
item['source'] = result['source']
|
||||||
item['source'] = result['source']
|
item['img_src'] = result['properties']['url']
|
||||||
item['img_src'] = result['properties']['url']
|
elif categories[0] == 'videos':
|
||||||
case 'videos':
|
item['template'] = 'videos.html'
|
||||||
item['template'] = 'videos.html'
|
item['length'] = result['video']['duration']
|
||||||
item['length'] = result['video']['duration']
|
|
||||||
|
|
||||||
results.append(item)
|
results.append(item)
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
|
@ -1847,13 +1847,19 @@ engines:
|
||||||
shortcut: braveimg
|
shortcut: braveimg
|
||||||
engine: brave
|
engine: brave
|
||||||
categories: images
|
categories: images
|
||||||
disabled: false
|
disabled: true
|
||||||
|
|
||||||
- name: brave.videos
|
- name: brave.videos
|
||||||
shortcut: bravevid
|
shortcut: bravevid
|
||||||
engine: brave
|
engine: brave
|
||||||
categories: videos
|
categories: videos
|
||||||
disabled: false
|
disabled: true
|
||||||
|
|
||||||
|
- name: brave.news
|
||||||
|
shortcut: bravenews
|
||||||
|
engine: brave
|
||||||
|
categories: news
|
||||||
|
disabled: true
|
||||||
|
|
||||||
- name: petalsearch
|
- name: petalsearch
|
||||||
shortcut: pts
|
shortcut: pts
|
||||||
|
|
Loading…
Reference in a new issue