
    i2                        S SK r S SKrS SKrS SKrS SKr\R
                  S    S:  a  S SKJr  S SKJ	r	J
r
  S SKJrJrJr  OS SKJr  S SKJr  S SKJ	r	J
r
  S SKJrJr   S SKJr  S	r/ SQrSrSrSrSrSrSr\ R:                  " S5      r\(       d  \ R:                  " S5      r\(       d  Sr\" \ R>                  RA                  \S5      5      r! \!RE                  5         Sr$ \ R>                  RK                  \ R>                  RM                  \'5      S    5      r( \ R>                  RA                  \(S5      r)S SK*r*\*RV                  " \)S5      r, \,R[                  5        V s/ sH  o R]                  5       PM     sn r/\,Ra                  5         C,S r1S r2S S jr3S r4   S!S jr5S r6g! \ a    S SKJr  S
r GNOf = f! \# a     Nf = fs  sn f ! \,Ra                  5         C,f = f! \# av    \ R>                  RA                  \(S5      r)\+" \)5       r,\,R[                  5        V s/ sH  o R]                  5       PM     Os  sn f sn r/SSS5         M  ! , (       d  f        N= ff = f! \# a    \$/r/ Nf = f)"    N   )LWPCookieJar)Requesturlopen)
quote_plusurlparseparse_qs)r   )r   r	   )BeautifulSoupTF)searchluckyget_random_user_agentget_tbszhttps://www.google.%(tld)s/zuhttps://www.google.%(tld)s/search?hl=%(lang)s&q=%(query)s&btnG=Google+Search&tbs=%(tbs)s&safe=%(safe)s&cr=%(country)szrhttps://www.google.%(tld)s/search?hl=%(lang)s&q=%(query)s&start=%(start)d&tbs=%(tbs)s&safe=%(safe)s&cr=%(country)szhttps://www.google.%(tld)s/search?hl=%(lang)s&q=%(query)s&num=%(num)d&btnG=Google+Search&tbs=%(tbs)s&safe=%(safe)s&cr=%(country)sz~https://www.google.%(tld)s/search?hl=%(lang)s&q=%(query)s&num=%(num)d&start=%(start)d&tbs=%(tbs)s&safe=%(safe)s&cr=%(country)s)hlqnumbtnGstarttbssafecrHOMEUSERHOME.z.google-cookiez2Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)zuser_agents.txt.gzrbzuser_agents.txtc                  6    [         R                  " [        5      $ )zQ
Get a random user agent string.

:rtype: str
:return: Random user agent string.
)randomchoiceuser_agents_list     T/var/www/html/tms-backend/venv/lib/python3.13/site-packages/googlesearch/__init__.pyr   r   {   s     ==)**r    c                 `    U R                  S5      n UR                  S5      nS[        5       -  $ )z
Helper function to format the tbs parameter.

:param datetime.date from_date: Python date object.
:param datetime.date to_date: Python date object.

:rtype: str
:return: Dates encoded in tbs format.
z%m/%d/%Yz-cdr:1,cd_min:%(from_date)s,cd_max:%(to_date)s)strftimevars)	from_dateto_dates     r!   r   r      s1     "":.Iz*G:TVCCr    c                    Uc  [         n[        U 5      nUR                  SU5        [        R	                  U5        U(       a  [        U5      nO[        R                  " 5       n[        X5S9n[        R                  XC5        UR                  5       nUR                  5          [        R                  5         U$ ! [         a     U$ f = f)a  
Request the given URL and return the response page, using the cookie jar.

:param str url: URL to retrieve.
:param str user_agent: User agent for the HTTP requests.
    Use None for the default.
:param bool verify_ssl: Verify the SSL certificate to prevent
    traffic interception attacks. Defaults to True.

:rtype: str
:return: Web page retrieved for the given URL.

:raises IOError: An exception is raised on error.
:raises urllib2.URLError: An exception is raised on error.
:raises urllib2.HTTPError: An exception is raised on error.
z
User-Agent)context)
USER_AGENTr   
add_header
cookie_jaradd_cookie_headerr   ssl_create_unverified_contextextract_cookiesreadclosesave	Exception)url
user_agent
verify_sslrequestresponser(   htmls          r!   get_pager:      s    " 
clG|Z0  )7#00274x1==?DNN K  Ks   #B9 9
CCc                      U R                  S5      (       a'  [        U S5      n[        UR                  5      S   S   n [        U S5      nUR                  (       a  SUR                  ;  a  U $ g g ! [
         a     g f = f)Nz/url?httpr   r   google)
startswithr   r	   querynetlocr3   )linkos     r!   filter_resultrC      s|     ??7##v&AAGG$S)!,D
 T6"880K 18  s   A+A0 0
A=<A=c              #     #    [        5       nSn[        U 5      n U
(       d  0 n
[         H"  nXR                  5       ;   d  M  [	        SU5      e   [        [        [        5       -  X5        U(       a*  US:X  a  [        [        5       -  nO;[        [        5       -  nO)US:X  a  [        [        5       -  nO[        [        5       -  nU(       a  X:  GaJ  UnU
R                  5        H)  u  nn[        U5      n[        U5      nUSU< SU< 3-   nM+     [        R                  " U5        [        UX5      n[        (       a  [!        US5      nO[!        U5      n UR#                  SS9R%                  S	5      nU HZ  n US   n[-        U5      nU(       d  M  [/        U5      nUU;   a  M0  UR1                  U5        Uv   US-  nU(       d  MS  X:  d  MZ    g   UU:X  a  gXe-  nUS:X  a  [        [        5       -  nO[        [        5       -  nU(       d  GMA  X:  a  GMI  gg! [&         a:    UR#                  S
S9nU(       a  UR)                  5         UR%                  S	5      n Nf = f! [*         a     M  f = f7f)a  
Search the given query string using Google.

:param str query: Query string. Must NOT be url-encoded.
:param str tld: Top level domain.
:param str lang: Language.
:param str tbs: Time limits (i.e "qdr:h" => last hour,
    "qdr:d" => last 24 hours, "qdr:m" => last month).
:param str safe: Safe search.
:param int num: Number of results per page.
:param int start: First result to retrieve.
:param int stop: Last result to retrieve.
    Use None to keep searching forever.
:param float pause: Lapse to wait between HTTP requests.
    A lapse too long will make the search slow, but a lapse too short may
    cause Google to block your IP. Your mileage may vary!
:param str country: Country or region to focus the search on. Similar to
    changing the TLD, but does not yield exactly the same results.
    Only Google knows why...
:param dict extra_params: A dictionary of extra HTTP GET
    parameters, which must be URL encoded. For example if you don't want
    Google to filter similar results you can set the extra_params to
    {'filter': '0'} which will append '&filter=0' to every query.
:param str user_agent: User agent for the HTTP requests.
    Use None for the default.
:param bool verify_ssl: Verify the SSL certificate to prevent
    traffic interception attacks. Defaults to True.

:rtype: generator of str
:return: Generator (iterator) that yields found URLs.
    If the stop parameter is None the iterator will loop forever.
r   zQGET parameter "%s" is overlapping with                 the built-in GET parameter
   &=zhtml.parserr   )idagbarhref   N)setr   url_parameterskeys
ValueErrorr:   url_homer$   url_next_pageurl_next_page_num
url_searchurl_search_numitemstimesleepis_bs4r
   findfindAllAttributeErrorclearKeyErrorrC   hashadd)r?   tldlangr   r   r   r   stoppausecountryextra_paramsr5   r6   hashescountbuiltin_paramr4   
last_countkvr9   soupanchorsrJ   rI   rA   hs                              r!   r   r      sO    J UF E uE
  (--//,  ( X
7 "9$&(C#df,C"9tv%C 46)C el 

 !&&(DAq1A1AQ*+C ) 	

5 Z4 6 }5D &D		(ii8i,44S9G Ay
 !&D T
AF{JJqM J QJEt5 <  	"9$&(C#df,CW dell:  	(999'D

ll3'G	(  sn   ;I4DI4H 4I4:I#?AI4	I4?I4I4I4AI I4I  I4#
I1-I40I11I4c                  *    [        [        U 0 UD65      $ )z
Shortcut to single-item search.

Same arguments as the main search function, but the return value changes.

:rtype: str
:return: URL found by Google.
)nextr   )argskwargss     r!   r   r   o  s     ''((r    )NT)comen0offrE   r   Ng       @ NNT)7osr   sysrW   r-   version_infohttp.cookiejarr   urllib.requestr   r   urllib.parser   r   r	   	cookieliburlliburllib2bs4r
   rY   ImportError__all__rQ   rT   rR   rU   rS   rN   getenvhome_folderpathjoinr+   loadr3   r)   abspathsplit__file__install_folderuser_agents_filegzipopenfp	readlinesstripr   r1   r   r   r:   rC   r   r   )_s   0r!   <module>r      sJ  < 
  
  
A+/;;&!(+!F

 )
!"3 <
 ii))J'K"'',,{4DEF
	OO
 B
$WW__RWW]]8%<Q%?@NC77<<8LMYY'.	35<<>B>a	>BHHJ+D""N* LM:>'+W-x	)}	  +FV  		$  CHHJ C77<<8IJ"#r35<<>B>a	>B $###C  $"|$s   F$ F9  7I 3G  G
 G6G
 9G  $F65F69GGG
 
GG   *I
I	H65	I	>II 	
I	II II 	I+*I+