
    i9                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	m
Z
 ddd	d
dddZddgZdZdZ	 d Zd Zde	fdZy)a.  `Hugging Face`_ search engine for SearXNG.

.. _Hugging Face: https://huggingface.co

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

The engine has the following additional settings:

- :py:obj:`huggingface_endpoint`

Configurations for endpoints:

.. code:: yaml

  - name: huggingface
    engine: huggingface
    shortcut: hf

  - name: huggingface datasets
    huggingface_endpoint: datasets
    engine: huggingface
    shortcut: hfd

  - name: huggingface spaces
    huggingface_endpoint: spaces
    engine: huggingface
    shortcut: hfs

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

    )	urlencode)datetime)SearxEngineAPIException)html_to_text)EngineResults
MainResultzhttps://huggingface.co/
Q108943604z&https://huggingface.co/docs/hub/en/apiTFJSON)websitewikidata_idofficial_api_documentationuse_official_apirequire_api_keyresultsitreposzhttps://huggingface.comodelsc                 8    t         dvrt        dt                y )N)datasetsr   spacesz#Unsupported Hugging Face endpoint: )huggingface_endpointr   )_s    */root/searxng/searx/engines/huggingface.pyinitr   A   s&    #CC%(KL`Ka&bcc D    c                 L    d| d}t          dt         dt        |       |d<   |S )N)	directionsearchz/api/?url)base_urlr   r   )queryparamsquery_paramss      r   requestr&   F   s8    L
  j&:%;1Y|=T<UVF5MMr   returnc           	         t               }| j                         }|D ]9  }t        dk7  rt         dt         d|d    }nt         d|d    }d }	 t	        j
                  |d   d      }g }|j                  d      r|j                  d|d           |j                  d      r|j                  d	|d   d
       |j                  d      r&|j                  ddj                  |d                 |j                  d      r|j                  d|d           t        |d   t        dj                  |            ||      }|j                  |       < |S # t        t        f$ r Y w xY w)Nr   /id	createdAtz%Y-%m-%dT%H:%M:%S.%fZlikeszLikes: 	downloadszDownloads: ,tagszTags: z, descriptionzDescription: z | )titlecontentr!   publishedDate)r   jsonr   r"   r   strptime
ValueError	TypeErrorgetappendjoinr   r   add)respr   dataentryr!   published_datecontentsitems           r   responserB   Q   sw   oG99;D 8+Ja 45QuT{mDCJad}-C	%..u[/ACZ[N 99WOOgeGn%56799[!OOk%*<Q)?@A99VOOfTYYuV}%=$>?@99]#OOmE-,@+ABC+ H!56(	
 	D9< N+ I& 		s   EE/.E/N)__doc__urllib.parser   r   searx.exceptionsr   searx.utilsr   searx.result_typesr   r   about
categoriesr"   r   r   r&   rB    r   r   <module>rK      si    D #  4 $ 8 )"J	 G_
# d
#m #r   