.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.wikidata.WDURLAttribute Class Reference
+ Inheritance diagram for searx.engines.wikidata.WDURLAttribute:
+ Collaboration diagram for searx.engines.wikidata.WDURLAttribute:

Public Member Functions

 __init__ (self, name, url_id=None, url_path_prefix=None, kwargs=None)
 
 get_str (self, result, language)
 
- Public Member Functions inherited from searx.engines.wikidata.WDAttribute
 __init__ (self, name)
 
 get_select (self)
 
 get_label (self, language)
 
 get_where (self)
 
 get_wikibase_label (self)
 
 get_group_by (self)
 
 __repr__ (self)
 

Public Attributes

 url_id = url_id
 
 url_path_prefix = url_path_prefix
 
 kwargs = kwargs
 
- Public Attributes inherited from searx.engines.wikidata.WDAttribute
 name = name
 

Static Public Attributes

str HTTP_WIKIMEDIA_IMAGE = 'http://commons.wikimedia.org/wiki/Special:FilePath/'
 

Static Private Attributes

str __slots__ = 'url_id', 'url_path_prefix', 'kwargs'
 

Detailed Description

Definition at line 599 of file wikidata.py.

Constructor & Destructor Documentation

◆ __init__()

searx.engines.wikidata.WDURLAttribute.__init__ ( self,
name,
url_id = None,
url_path_prefix = None,
kwargs = None )
:param url_id: ID matching one key in ``external_urls.json`` for
    converting IDs to full URLs.

:param url_path_prefix: Path prefix if the values are of format
    ``account@domain``.  If provided, value are rewritten to
    ``https://<domain><url_path_prefix><account>``.  For example::

      WDURLAttribute('P4033', url_path_prefix='/@')

    Adds Property `P4033 <https://www.wikidata.org/wiki/Property:P4033>`_
    to the wikidata query.  This field might return for example
    ``libreoffice@fosstodon.org`` and the URL built from this is then:

    - account: ``libreoffice``
    - domain: ``fosstodon.org``
    - result url: https://fosstodon.org/@libreoffice

Definition at line 605 of file wikidata.py.

605 def __init__(self, name, url_id=None, url_path_prefix=None, kwargs=None):
606 """
607 :param url_id: ID matching one key in ``external_urls.json`` for
608 converting IDs to full URLs.
609
610 :param url_path_prefix: Path prefix if the values are of format
611 ``account@domain``. If provided, value are rewritten to
612 ``https://<domain><url_path_prefix><account>``. For example::
613
614 WDURLAttribute('P4033', url_path_prefix='/@')
615
616 Adds Property `P4033 <https://www.wikidata.org/wiki/Property:P4033>`_
617 to the wikidata query. This field might return for example
618 ``libreoffice@fosstodon.org`` and the URL built from this is then:
619
620 - account: ``libreoffice``
621 - domain: ``fosstodon.org``
622 - result url: https://fosstodon.org/@libreoffice
623 """
624
625 super().__init__(name)
626 self.url_id = url_id
627 self.url_path_prefix = url_path_prefix
628 self.kwargs = kwargs
629

References __init__().

Referenced by __init__().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Function Documentation

◆ get_str()

searx.engines.wikidata.WDURLAttribute.get_str ( self,
result,
language )

Reimplemented from searx.engines.wikidata.WDAttribute.

Definition at line 630 of file wikidata.py.

630 def get_str(self, result, language):
631 value = result.get(self.name + 's')
632 if not value:
633 return None
634
635 value = value.split(',')[0]
636 if self.url_id:
637 url_id = self.url_id
638 if value.startswith(WDURLAttribute.HTTP_WIKIMEDIA_IMAGE):
639 value = value[len(WDURLAttribute.HTTP_WIKIMEDIA_IMAGE) :]
640 url_id = 'wikimedia_image'
641 return get_external_url(url_id, value)
642
643 if self.url_path_prefix:
644 [account, domain] = value.split('@', 1)
645 return f"https://{domain}{self.url_path_prefix}{account}"
646
647 return value
648
649

References searx.engines.wikidata.WDAttribute.name, url_id, and url_path_prefix.

Member Data Documentation

◆ __slots__

str searx.engines.wikidata.WDURLAttribute.__slots__ = 'url_id', 'url_path_prefix', 'kwargs'
staticprivate

Definition at line 603 of file wikidata.py.

◆ HTTP_WIKIMEDIA_IMAGE

str searx.engines.wikidata.WDURLAttribute.HTTP_WIKIMEDIA_IMAGE = 'http://commons.wikimedia.org/wiki/Special:FilePath/'
static

Definition at line 601 of file wikidata.py.

◆ kwargs

searx.engines.wikidata.WDURLAttribute.kwargs = kwargs

Definition at line 628 of file wikidata.py.

◆ url_id

searx.engines.wikidata.WDURLAttribute.url_id = url_id

Definition at line 626 of file wikidata.py.

Referenced by get_str().

◆ url_path_prefix

searx.engines.wikidata.WDURLAttribute.url_path_prefix = url_path_prefix

Definition at line 627 of file wikidata.py.

Referenced by get_str().


The documentation for this class was generated from the following file: