.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
steam.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Steam (store) for SearXNG."""
3
4from urllib.parse import urlencode
5
6from searx.utils import html_to_text
7from searx.result_types import EngineResults, MainResult
8
9about = {
10 "website": 'https://store.steampowered.com/',
11 "wikidata_id": 'Q337535',
12 "use_official_api": False,
13 "require_api_key": False,
14 "results": 'JSON',
15}
16
17categories = []
18
19base_url = "https://store.steampowered.com"
20
21
22def request(query, params):
23 query_params = {"term": query, "cc": "us", "l": "en"}
24 params['url'] = f'{base_url}/api/storesearch/?{urlencode(query_params)}'
25 return params
26
27
28def response(resp) -> EngineResults:
29 results = EngineResults()
30 search_results = resp.json()
31
32 for item in search_results.get('items', []):
33 app_id = item.get('id')
34
35 currency = item.get('price', {}).get('currency', 'USD')
36 price = item.get('price', {}).get('final', 0) / 100
37
38 platforms = ', '.join([platform for platform, supported in item.get('platforms', {}).items() if supported])
39
40 content = [f'Price: {price:.2f} {currency}', f'Platforms: {platforms}']
41
42 results.add(
44 title=item.get('name'),
45 content=html_to_text(' | '.join(content)),
46 url=f'{base_url}/app/{app_id}',
47 thumbnail=item.get('tiny_image', ''),
48 )
49 )
50
51 return results
EngineResults response(resp)
Definition steam.py:28
request(query, params)
Definition steam.py:22