Skip to content

Commit

Permalink
[feat] engine: implementation of rotten tomatoes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnyro authored and return42 committed Dec 11, 2023
1 parent dda74fc commit 8a4104b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
60 changes: 60 additions & 0 deletions searx/engines/rottentomatoes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
# lint: pylint
"""RottenTomatoes (movies)
"""

from urllib.parse import quote_plus
from lxml import html
from searx.utils import eval_xpath, eval_xpath_list, extract_text

# about
about = {
"website": 'https://www.rottentomatoes.com/',
"wikidata_id": 'Q105584',
"official_api_documentation": None,
"use_official_api": False,
"require_api_key": False,
"results": 'HTML',
}
categories = ['movies']

base_url = "https://www.rottentomatoes.com"

results_xpath = "//search-page-media-row"
url_xpath = "./a[1]/@href"
title_xpath = "./a/img/@alt"
img_src_xpath = "./a/img/@src"
release_year_xpath = "concat('From ', string(./@releaseyear))"
score_xpath = "concat('Score: ', string(./@tomatometerscore))"
cast_xpath = "concat('Starring ', string(./@cast))"


def request(query, params):
params["url"] = f"{base_url}/search?search={quote_plus(query)}"
return params


def response(resp):
results = []

dom = html.fromstring(resp.text)

for result in eval_xpath_list(dom, results_xpath):
content = []
for xpath in (release_year_xpath, score_xpath, cast_xpath):
info = extract_text(eval_xpath(result, xpath))

# a gap in the end means that no data was found
if info and info[-1] != " ":
content.append(info)

results.append(
{
'url': extract_text(eval_xpath(result, url_xpath)),
'title': extract_text(eval_xpath(result, title_xpath)),
'content': ', '.join(content),
'img_src': extract_text(eval_xpath(result, img_src_xpath)),
}
)

return results
5 changes: 5 additions & 0 deletions searx/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,11 @@ engines:
shortcut: re
page_size: 25

- name: rottentomatoes
engine: rottentomatoes
shortcut: rt
disabled: true

# Required dependency: redis
# - name: myredis
# shortcut : rds
Expand Down

0 comments on commit 8a4104b

Please sign in to comment.