.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.archlinux Namespace Reference

Functions

 request (query, params)
 
 response (resp)
 
 fetch_traits (EngineTraits engine_traits)
 

Variables

logging logger .Logger
 
dict about
 
list categories = ['it', 'software wikis']
 
bool paging = True
 
str main_wiki = 'wiki.archlinux.org'
 

Detailed Description

Arch Linux Wiki
~~~~~~~~~~~~~~~

This implementation does not use a official API: Mediawiki provides API, but
Arch Wiki blocks access to it.

Function Documentation

◆ fetch_traits()

searx.engines.archlinux.fetch_traits ( EngineTraits engine_traits)
Fetch languages from Archlinux-Wiki.  The location of the Wiki address of a
language is mapped in a :py:obj:`custom field
<searx.enginelib.traits.EngineTraits.custom>` (``wiki_netloc``).  Depending
on the location, the ``title`` argument in the request is translated.

.. code:: python

   "custom": {
     "wiki_netloc": {
       "de": "wiki.archlinux.de",
        # ...
       "zh": "wiki.archlinuxcn.org"
     }
     "title": {
       "de": "Spezial:Suche",
        # ...
       "zh": "Special:\u641c\u7d22"
     },
   },

Definition at line 96 of file archlinux.py.

96def fetch_traits(engine_traits: EngineTraits):
97 """Fetch languages from Archlinux-Wiki. The location of the Wiki address of a
98 language is mapped in a :py:obj:`custom field
99 <searx.enginelib.traits.EngineTraits.custom>` (``wiki_netloc``). Depending
100 on the location, the ``title`` argument in the request is translated.
101
102 .. code:: python
103
104 "custom": {
105 "wiki_netloc": {
106 "de": "wiki.archlinux.de",
107 # ...
108 "zh": "wiki.archlinuxcn.org"
109 }
110 "title": {
111 "de": "Spezial:Suche",
112 # ...
113 "zh": "Special:\u641c\u7d22"
114 },
115 },
116
117 """
118 # pylint: disable=import-outside-toplevel
119 from searx.network import get # see https://github.com/searxng/searxng/issues/762
120
121 engine_traits.custom['wiki_netloc'] = {}
122 engine_traits.custom['title'] = {}
123
124 title_map = {
125 'de': 'Spezial:Suche',
126 'fa': 'ویژه:جستجو',
127 'ja': '特別:検索',
128 'zh': 'Special:搜索',
129 }
130
131 resp = get('https://wiki.archlinux.org/')
132 if not resp.ok: # type: ignore
133 print("ERROR: response from wiki.archlinux.org is not OK.")
134
135 dom = lxml.html.fromstring(resp.text) # type: ignore
136 for a in eval_xpath_list(dom, "//a[@class='interlanguage-link-target']"):
137
138 sxng_tag = language_tag(babel.Locale.parse(a.get('lang'), sep='-'))
139 # zh_Hans --> zh
140 sxng_tag = sxng_tag.split('_')[0]
141
142 netloc = urlparse(a.get('href')).netloc
143 if netloc != 'wiki.archlinux.org':
144 title = title_map.get(sxng_tag)
145 if not title:
146 print("ERROR: title tag from %s (%s) is unknown" % (netloc, sxng_tag))
147 continue
148 engine_traits.custom['wiki_netloc'][sxng_tag] = netloc
149 engine_traits.custom['title'][sxng_tag] = title # type: ignore
150
151 eng_tag = extract_text(eval_xpath_list(a, ".//span"))
152 engine_traits.languages[sxng_tag] = eng_tag # type: ignore
153
154 engine_traits.languages['en'] = 'English'

◆ request()

searx.engines.archlinux.request ( query,
params )

Definition at line 43 of file archlinux.py.

43def request(query, params):
44
45 sxng_lang = params['searxng_locale'].split('-')[0]
46 netloc: str = traits.custom['wiki_netloc'].get(sxng_lang, main_wiki) # type: ignore
47 title: str = traits.custom['title'].get(sxng_lang, 'Special:Search') # type: ignore
48 base_url = 'https://' + netloc + '/index.php?'
49 offset = (params['pageno'] - 1) * 20
50
51 if netloc == main_wiki:
52 eng_lang: str = traits.get_language(sxng_lang, 'English') # type: ignore
53 query += ' (' + eng_lang + ')'
54 # wiki.archlinux.org is protected by anubis
55 # - https://github.com/searxng/searxng/issues/4646#issuecomment-2817848019
56 params['headers']['User-Agent'] = "SearXNG"
57 elif netloc == 'wiki.archlinuxcn.org':
58 base_url = 'https://' + netloc + '/wzh/index.php?'
59
60 args = {
61 'search': query,
62 'title': title,
63 'limit': 20,
64 'offset': offset,
65 'profile': 'default',
66 }
67
68 params['url'] = base_url + urlencode(args)
69 return params
70
71

◆ response()

searx.engines.archlinux.response ( resp)

Definition at line 72 of file archlinux.py.

72def response(resp):
73
74 results = []
75 dom = lxml.html.fromstring(resp.text) # type: ignore
76
77 # get the base URL for the language in which request was made
78 sxng_lang = resp.search_params['searxng_locale'].split('-')[0]
79 netloc: str = traits.custom['wiki_netloc'].get(sxng_lang, main_wiki) # type: ignore
80 base_url = 'https://' + netloc + '/index.php?'
81
82 for result in eval_xpath_list(dom, '//ul[@class="mw-search-results"]/li'):
83 link = eval_xpath_getindex(result, './/div[@class="mw-search-result-heading"]/a', 0)
84 content = extract_text(result.xpath('.//div[@class="searchresult"]'))
85 results.append(
86 {
87 'url': urljoin(base_url, link.get('href')), # type: ignore
88 'title': extract_text(link),
89 'content': content,
90 }
91 )
92
93 return results
94
95

Variable Documentation

◆ about

dict searx.engines.archlinux.about
Initial value:
1= {
2 "website": 'https://wiki.archlinux.org/',
3 "wikidata_id": 'Q101445877',
4 "official_api_documentation": None,
5 "use_official_api": False,
6 "require_api_key": False,
7 "results": 'HTML',
8}

Definition at line 28 of file archlinux.py.

◆ categories

list searx.engines.archlinux.categories = ['it', 'software wikis']

Definition at line 38 of file archlinux.py.

◆ logger

logging searx.engines.archlinux.logger .Logger

Definition at line 23 of file archlinux.py.

◆ main_wiki

str searx.engines.archlinux.main_wiki = 'wiki.archlinux.org'

Definition at line 40 of file archlinux.py.

◆ paging

bool searx.engines.archlinux.paging = True

Definition at line 39 of file archlinux.py.