Files
searxng/searx/engines/findthatmeme.py
Onev 9e25585aec [refactor] engines: use datetime.fromisoformat instead of datetime.strptime where possible (#6394)
Refactor engines that parse ISO 8601 dates with strptime to use
fromisoformat instead. In most cases this is a direct replacement of
strptime(text, "format") with fromisoformat(text).

For engines where the source has a trailing "Z" that strptime consumed
as a literal (e.g. "%Y-%m-%dT%H:%M:%S.%fZ" in huggingface.py), add
rstrip("Z") to keep the output naive and preserve the existing behavior.

In sogou.py the date is extracted with a regular expression, which can
yield strings like "2026-7-11". strptime accepts this via its format
string, but fromisoformat does not. To preserve the existing behavior
and satisfy the format fromisoformat expects, add zero-padding for the
month and day.

Closes: #6098
---------
Signed-off-by: OneVth <onebrotravel@gmail.com>
2026-07-13 17:46:56 +02:00

55 lines
1.5 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""FindThatMeme (Images)"""
from json import dumps
from datetime import datetime
from searx.utils import humanize_bytes
about = {
"website": 'https://findthatmeme.com',
"official_api_documentation": None,
"use_official_api": False,
"require_api_key": False,
"results": "JSON",
}
base_url = "https://findthatmeme.com/api/v1/search"
categories = ['images']
paging = True
def request(query, params):
start_index = (params["pageno"] - 1) * 50
data = {"search": query, "offset": start_index}
params["url"] = base_url
params["method"] = 'POST'
params['headers']['content-type'] = "application/json"
params['data'] = dumps(data)
return params
def response(resp):
search_res = resp.json()
results = []
for item in search_res:
img = 'https://s3.thehackerblog.com/findthatmeme/' + item['image_path']
thumb = 'https://s3.thehackerblog.com/findthatmeme/thumb/' + item.get('thumbnail', '')
date = datetime.fromisoformat(item["updated_at"].split("T")[0])
formatted_date = datetime.fromtimestamp(date.timestamp())
results.append(
{
'url': item.get('source_page_url'),
'title': item.get('source_site'),
'img_src': img if item['type'] == 'IMAGE' else thumb,
'filesize': humanize_bytes(item['meme_file_size']),
'publishedDate': formatted_date,
'template': 'images.html',
}
)
return results