.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
 
EngineTraits traits
 
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 93 of file archlinux.py.

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

◆ response()

searx.engines.archlinux.response ( resp)

Definition at line 69 of file archlinux.py.

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

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.

◆ traits

EngineTraits searx.engines.archlinux.traits

Definition at line 25 of file archlinux.py.