
    i>              	           d Z ddlmZ ddlmZ ddlmZmZ ddlmZ ddl	m
Z
 ddd	d
d
ddZdgZdZdZdZdZdZ	 dddddZd Zde
fdZddeeef   dededefdZy	)aJ  Reuters_ (news) is an international news agency.

.. _Reuters: https://www.reuters.com

Configuration
=============

The engine has the following additional settings:

- :py:obj:`sort_order`

.. code:: yaml

   - name: reuters
     engine: reuters
     shortcut: reu
     sort_order: "relevance"

Implementations
===============

    )dumps)
quote_plus)datetime	timedelta)parser)EngineResultszhttps://www.reuters.comQ130879NFJSON)websitewikidata_idofficial_api_documentationuse_official_apirequire_api_keyresultsnewsT   	relevance         im  )dayweekmonthyearc                 
   | |d   dz
  t         z  t        t         dd}|d   r@t        |d      }t        j                         t        |      z
  }|j                         |d<   t         dt        t        |             |d	<   |S )
Npagenor   reuters)keywordoffsetorderbysizer   
time_range)days
start_datez5/pf/api/v3/content/fetch/articles-by-search-v2?query=url)
results_per_page
sort_ordertime_range_duration_mapr   nowr   	isoformatbase_urlr   r   )queryparamsargstime_diff_daysr$   s        &/root/searxng/searx/engines/reuters.pyrequestr1   ;   s    (#a'+;; D l01EF\\^i^&DD
'113\j UV`afgkalVmUnoF5MM    returnc                    t               }| j                         }|j                  d      s|S |d   j                  dg       D ]  }|j                  |j                  j                  t        |d   z   |d   |d   t        |j                  di       d      |j                  d	i       j                  d
      t        j                  |d                       |S )Nresultarticlescanonical_urlwebdescription	thumbnailP   )heightkickernamedisplay_time)r%   titlecontentr:   metadatapublishedDate)
r   jsongetaddtypes
MainResultr+   
resize_urlr   isoparse)respres	resp_jsonr5   s       r0   responserN   L   s    
/C		I=="
H%))*b9 

II  vo66Um}-$VZZR%@LHb155f=$oof^.DE ! 		


 Jr2   r:   widthr<   c                     | j                  d      }|syt        |      dkD  r|dt        |       z  }t        |      dkD  r|dt        |       z  }|S )a  Generates a URL for Reuter's thumbnail with the dimensions *width* and
    *height*.  If no URL can be generated from the *thumbnail data*, an empty
    string will be returned.

    width: default is *unset* (``0``)
      Image width in pixels (negative values are ignored). If only width is
      specified, the height matches the original aspect ratio.

    height: default is *unset* (``0``)
      Image height in pixels (negative values are ignored). If only height is
      specified, the width matches the original aspect ratio.

    The file size of a full-size image is usually several MB; when reduced to a
    height of, for example, 80 points, only a few KB remain!

    Fields of the *thumbnail data* (``result.articles.[<int>].thumbnail``):

    thumbnail.url:
      Is a full-size image (>MB).

    thumbnail.width & .height:
      Dimensions of the full-size image.

    thumbnail.resizer_url:
      Reuters has a *resizer* `REST-API for the images`_, this is the URL of the
      service. This URL includes the ``&auth`` argument, other arguments are
      ``&width=<int>`` and ``&height=<int>``.

    .. _REST-API for the images:
        https://dev.arcxp.com/photo-center/image-resizer/resizer-v2-how-to-transform-images/#query-parameters
    resizer_url r   z&width=z&height=)rE   int)r:   rO   r<   r%   s       r0   rI   rI   a   s^    B --
&C
5zA~U%%
6{Q#f+''Jr2   )r   r   )__doc__rD   r   urllib.parser   r   r   dateutilr   searx.result_typesr   about
categoriestime_range_supportpagingr+   r&   r'   r(   r1   rN   dictstrrS   rI    r2   r0   <module>r_      s   .  # (  , )"&	 X
 	$ 
 V 	 "m *($sCx. ( (# (c (r2   