
    6j                         d Z ddlZddlZddlmZ ddlmZ ddlmZ  ej	        e
          Z G d dee                   ZdS )Grokipedia text search engine.    N)Any)BaseSearchEngine)
TextResultc                       e Zd ZdZdZdZdZdZdZdZ		 dde
d	e
d
e
de
dz  dede
dee
ef         fdZde
dee         fdZdS )
Grokipediar   
grokipediatextgffffff?z$https://grokipedia.com/api/typeaheadGET   queryregion
safesearch	timelimitNpagekwargsreturnc                     |dd}|S )z'Build a payload for the search request.1)r   limit )selfr   r   r   r   r   r   payloads           Y/root/.hermes/hermes-agent/venv/lib64/python3.11/site-packages/ddgs/engines/grokipedia.pybuild_payloadzGrokipedia.build_payload   s     -2C"@"@    	html_textc                    t          j        |          }|                    dg           }|sg S t                      }|d                             dd                              d          |_        |d                             dd          }d|v r|                    dd          d         n||_        d	|d         d
          |_        |gS )z&Extract search results from html text.resultsr   title _snippetz

r   zhttps://grokipedia.com/page/slug)	jsonloadsgetr   stripr    splitbodyhref)r   r   	json_dataitemsresultr*   s         r   extract_resultszGrokipedia.extract_results%   s    Jy))	i,, 	IQx||GR0066s;;Qx||Ir**28D..djj++A..dGU1Xf5EGGxr   )r   )__name__
__module____qualname____doc__namecategoryproviderpriority
search_urlsearch_methodstrintdictr   r   listr   r/   r   r   r   r   r      s        ((DHHH7JM    	
 :   
c3h    j1A      r   r   )r3   r%   loggingtypingr   	ddgs.baser   ddgs.resultsr   	getLoggerr0   loggerr   r   r   r   <module>rD      s    $ $         & & & & & & # # # # # #		8	$	$$ $ $ $ $!*- $ $ $ $ $r   