
    6jW                         d Z ddlZddlmZ ddlmZ ddlmZmZmZ ddl	m
Z
mZ ddlmZ ddlmZ  ej        d	ej                  Zd
edefdZ G d dee                   ZdS )z Bing news engine implementation.    N)Mapping)suppress)datetime	timedeltatimezone)AnyClassVar)BaseSearchEngine)
NewsResultuA   \b(\d+)\s*(days|tagen|jours|giorni|dias|días|дн\.|день)?\bpub_date_strreturnc                 "   g d}|D ]t}t          t                    5  t          j        | |                              t
          j                                                  cddd           c S # 1 swxY w Y   ut          	                    |           }|rwt          |                    d                    }t          j        t
          j                  t          |          z
                      d                                          S | S )zExtract date from string.)z%d.%m.%Yz%m/%d/%Yz%d/%m/%YN   )daysr   )microsecond)r   
ValueErrorr   strptime
astimezoner   utc	isoformatDATE_REsearchintgroupnowr   replace)r   date_formatsdate_formatmatchdays_agos        X/root/.hermes/hermes-agent/venv/lib64/python3.11/site-packages/ddgs/engines/bing_news.pyextract_dater"      sS    877L# e ej!! 	e 	e$\;??JJ8<XXbbdd	e 	e 	e 	e 	e 	e 	e 	e 	e 	e 	e 	e 	e 	e 	e 	e 	e 	e 	e NN<((E ju{{1~~&&X\**YH-E-E-EENN[\N]]ggiii s   AA00A4	7A4	c                       e Zd ZU dZdZdZdZdZdZdZ	ddd	d
dddZ
eeeef                  ed<   	 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e         dee         fdZdS )BingNewszBing news engine.bingnewsz,https://www.bing.com/news/infinitescrollajaxGETz#//div[contains(@class, 'newsitem')]z!.//span[@aria-label]//@aria-labelz@data-titlez .//div[@class='snippet']//text()z@urlz%.//a[contains(@class, 'image')]//@srcz@data-author)datetitlebodyurlimagesourceelements_xpathr   queryregion
safesearch	timelimitNpagekwargsr   c                     |                                                     d          \  }}|d|dz  dz    | ||d}	|rddddd	|         |	d
<   |	S )z,Build a payload for the Bing search request.-1
   r   )qInfiniteScrollfirstSFXccsetlangzinterval="4"zinterval="7"zinterval="9")dwmyqft)lowersplit)
selfr/   r0   r1   r2   r3   r4   countrylangpayloads
             r!   build_payloadzBingNews.build_payload5   s     ,,S11!r	A'9
 
  	####	 
 GEN     resultsc                     |D ]L}t          |j                  |_        |j        r#d|j                            d          d          nd|_        M|S )zPost-process search results.zhttps://www.bing.com&r    )r"   r(   r,   rE   )rF   rL   results      r!   post_extract_resultszBingNews.post_extract_resultsQ   s^     	g 	gF&v{33FKRXR^fN&,2D2DS2I2I!2LNNNdfFLLrK   )r   )__name__
__module____qualname____doc__namecategoryprovider
search_urlsearch_methoditems_xpathr.   r	   r   str__annotations__r   dictr   rJ   listr   rQ    rK   r!   r$   r$   !   s        DHH?JM7K328 3 3NHWS#X./       	
 :   
c3h   8D,< jAQ      rK   r$   )rU   recollections.abcr   
contextlibr   r   r   r   typingr   r	   	ddgs.baser
   ddgs.resultsr   compile
IGNORECASEr   r\   r"   r$   r`   rK   r!   <module>ri      s   & & 				 # # # # # #       2 2 2 2 2 2 2 2 2 2                 & & & & & & # # # # # #
"*Y[][h
i
is s    $5 5 5 5 5
+ 5 5 5 5 5rK   