.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
bpb.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""BPB refers to ``Bundeszentrale für poltische Bildung``, which is a German
3governmental institution aiming to reduce misinformation by providing resources
4about politics and history.
5"""
6
7from datetime import datetime
8from urllib.parse import urlencode
9
10about = {
11 'website': "https://www.bpb.de",
12 'official_api_documentation': None,
13 'use_official_api': False,
14 'require_api_key': False,
15 'results': 'JSON',
16 'language': 'de',
17}
18
19paging = True
20categories = ['general']
21
22
23base_url = "https://www.bpb.de"
24
25
26def request(query, params):
27 args = {
28 'query[term]': query,
29 'page': params['pageno'] - 1,
30 'sort[direction]': 'descending',
31 'payload[nid]': 65350,
32 }
33 params['url'] = f"{base_url}/bpbapi/filter/search?{urlencode(args)}"
34 return params
35
36
37def response(resp):
38 results = []
39
40 json_resp = resp.json()
41
42 for result in json_resp['teaser']:
43 thumbnail = None
44 if result['teaser']['image']:
45 thumbnail = base_url + result['teaser']['image']['sources'][-1]['url']
46
47 metadata = result['extension']['overline']
48 authors = ', '.join(author['name'] for author in result['extension'].get('authors', []))
49 if authors:
50 metadata += f" | {authors}"
51
52 publishedDate = None
53 if result['extension'].get('publishingDate'):
54 publishedDate = datetime.utcfromtimestamp(result['extension']['publishingDate'])
55
56 results.append(
57 {
58 'url': base_url + result['teaser']['link']['url'],
59 'title': result['teaser']['title'],
60 'content': result['teaser']['text'],
61 'thumbnail': thumbnail,
62 'publishedDate': publishedDate,
63 'metadata': metadata,
64 }
65 )
66
67 return results
response(resp)
Definition bpb.py:37
request(query, params)
Definition bpb.py:26