
    FEi%                        d Z ddlZddlmZ 	 ddlZddlm	Z	m
Z
mZmZmZ ddlmZ dd	lmZ  ej$                          ej&                  d
d      dId              Zej+                          ej,                  dddd       ej,                  d ej.                  g dd      ddd       ej,                  ddd       ej,                  ddd       ej,                  d ed!d"d      d#ed$ed%ed&ed'eddfd(                                          Zej+                          ej,                  dddd       ej,                  d) ej.                  g d*d      d+d,d       ej,                  d-d.d/d       ej,                  d ej.                  g d0d      d1dd       ej,                  d2dd3       ej,                  d4 ej.                  ed      d5d6d       ej,                  d7 ej8                         d8d9d      d#ed:ed;ed$ed<ed=ed>eddfd?                                                        Zej+                          ej,                  d@dA ej.                  g dBd      ddCD      dAeddfdE              Zej+                         dIdF       ZdIdGZ e!dHk(  r e         yy# e$ r&  ed        ed        ej                  d       Y w xY w)Jzj
Command-line interface for trendspyg.

Provides easy access to Google Trends data via terminal commands.
    N)Optionalz.Error: click is required for CLI functionalityz(Install with: pip install trendspyg[cli]   )	COUNTRIES	US_STATES
CATEGORIESTIME_PERIODSSORT_OPTIONS)download_google_trends_csv)download_google_trends_rssz0.4.2	trendspyg)version	prog_namereturnc                       y)z
    trendspyg - Google Trends data downloader

    Free, open-source tool for downloading Google Trends data.
    Supports 125 countries, 51 US states, 20 categories.
    N r       Y/home/sietch6/trending-topics-pipeline/venv/lib/python3.12/site-packages/trendspyg/cli.pyclir      s     	r   z--geoUSz)Country/region code (e.g., US, GB, US-CA)T)defaulthelpshow_defaultz--output)dict	dataframejsoncsvF)case_sensitiver   zOutput format)typer   r   r   z--no-imageszExclude images from output)is_flagr   z--no-articlesz!Exclude news articles from outputz--max-articles   zMaximum articles per trendgeooutput	no_imagesno_articlesmax_articlesc           	         t        j                  d|  d       	 t        | || | |      }|dk(  rt        j                  dt        |       d       t        j                  d       t	        |d      D ]  \  }}t        j                  d	| d
|d   j                                 t        j                  d|d           t        j                  d|d           d|v r&|d   d   rt        j                  d|d   d           d|v r|d   rt        j                  dt        |d          d       t	        |d   dd d      D ]h  \  }}	t        j                  d| d
|	d           t        j                  d|	d           |t        |d   dd       k  sTt        j                  d       j t        |d         dkD  r(t        j                  dt        |d         dz
   d       t        j                  d|d            |t        |      k  st        j                  d!        n|d"k(  rHt        j                  d#t        |       d$       t        j                  |j                  d%&             n5|d'k(  rt        j                  |       n|d(k(  rt        j                  |       t        j                  d)       y# t        $ r9}
t        j                  d*|
 d+,       t        j                  d       Y d}
~
yd}
~
ww xY w)-z
    Download trends via RSS feed (fast, rich media).

    Examples:
        trendspyg rss --geo US
        trendspyg rss --geo GB --output json
        trendspyg rss --geo JP --no-images --no-articles
    zDownloading RSS trends for ...)r!   output_formatinclude_imagesinclude_articlesmax_articles_per_trendr   z
Found z	 trends:
zF======================================================================r   
. trendz   Traffic: trafficz   Published: 	publishedimageurlz
   Image: sourcenews_articlesz   News Articles (z):N   z     headlinez        Source:  z     ... and z more articles   Explore: explore_linkzF----------------------------------------------------------------------r   z
DataFrame with z rowsr    )max_rowsr   r   z
[OK] Success![ERROR] Terr)
clickechor   len	enumerateupper	to_string	Exceptionsysexit)r!   r"   r#   r$   r%   resultir.   jarticlees              r   rssrL   #   s   \ 
JJ,SE56.+ (=!,_#/
 VJJ#f+j9:JJv%fa0 '5

Rs"U7^%9%9%;$<=>

\%	*:);<=

^E+,>+?@Ae#gu(=JJE'N8,D+EFG"e+o0FJJ!3Co8N4O3PPRST&/o0Fr0JA&N +
7

U1#R
0C/D#EF

%5gh6G5H#IJs5#9"1#=>>!JJrN	+
 512Q6

]3u_7M3NQR3R2SSa#bc

\%*?)@ABs6{?JJv&+', {"JJ*3v;-u=>JJv'''34vJJvu_JJv

_& 

XaS>t,s&   FK	 A9K	 B0K	 		L/LLz--hours)42448168rN   zTime period in hoursz
--categoryallz,Category filter (e.g., sports, tech, health))r   r   r   parquetr   z--active-onlyzShow only active/rising trendsz--sort	relevancez
Sort orderz--output-dirz./downloadszOutput directory for fileshourscategoryactive_onlysort
output_dirc           	         t        j                  d|  d       t        j                  d| d       t        j                  d|        t        j                  d|        	 t        | t        |      |||||      }|dk(  rt        j                  d	|        y|d
k(  rt        j                  d	|        y|dk(  rt        j                  d	|        y|dk(  rt        j                  dt	        |       d       t        j                  d       t        |j                  d      j                         d      D ]  \  }\  }	}
t        j                  d| d|
d   j                                 t        j                  d|
d           d|
v r |
d   rt        j                  d|
d           d|
v rJ|
d   rE|
d   }t	        t        |            dkD  rt        |      dd dz   }t        j                  d|        t        j                  d|
d           |dk  s|t	        |      k  st        j                  d       
 t	        |      dkD  r%t        j                  d t	        |      dz
   d!       t        j                  d"t	        |       d#       yy# t        $ r9}t        j                  d$| d%&       t        j                  d       Y d}~yd}~ww xY w)'z
    Download trends via CSV export (comprehensive, filtered).

    Examples:
        trendspyg csv --geo US
        trendspyg csv --geo US-CA --hours 168 --category sports
        trendspyg csv --geo GB --active-only --output json
    zDownloading CSV trends for r'   z  Time period: hz  Category: z  Active only: )r!   rT   rU   r(   rV   sort_bydownload_dirr   z
[OK] Downloaded: r   rR   r   z
Top 10 Trends (Total: ):
zd====================================================================================================
   r   r,   r-   Trendsz   Search Volume: zSearch volumeStartedz   Started: zTrend breakdownd   Nz   Related: r8   zExplore linkzd----------------------------------------------------------------------------------------------------z	
... and z more trendsz
[OK] Total: z trendsr;   Tr<   )r>   r?   r
   intr@   rA   headiterrowsrB   strrD   rE   rF   )r!   rT   rU   r"   rV   rW   rX   rG   rH   idxrow	breakdownrK   s                r   r   r      s   ~ 
JJ,SE56	JJq)*	JJhZ()	JJ./,+e* ##
 U?JJ,VH56vJJ,VH56y JJ,VH56{"JJ1#f+dCDJJw "+6;;r?+C+C+Eq!I (:C

Rs"S]%8%8%:$;<=

/O0D/EFG#IJJc)n-=>?$+4E0F #$5 6I3y>*S0$'	N4C$85$@	JJi[9:

\#n*=)>?@r6a#f+oJJw'( 6{R

ZFb(8'9FGJJF}G<=/ #2  

XaS>t,s8   $8J! J! ;J! E	J! #J! 2A-J! !	K#*/KK#z--type	list_type)	countriesstates
categoriesrT   zType of list to show)r   requiredr   c                 *   | dk(  rht        j                  dt        t               d       t	        t        j
                               D ]!  \  }}t        j                  d|dd|        # y| dk(  rht        j                  dt        t               d       t	        t        j
                               D ]!  \  }}t        j                  d|d	d|        # y| d
k(  rat        j                  dt        t               d       t	        t        j                               D ]  }t        j                  d|         y| dk(  rNt        j                  d       t        j
                         D ]!  \  }}t        j                  d|dd|        # yy)z
    List available options.

    Examples:
        trendspyg list --type countries
        trendspyg list --type states
        trendspyg list --type categories
    rj   z
Available Countries (r]   z  rM   z - rk   z
Available US States (8rl   z
Available Categories (rT   z
Available Time Periods:
3z	 hours - N)
r>   r?   r@   r   sorteditemsr   r   keysr   )ri   codenamecatrT   labels         r   listrx      se   " K

,S^,<DAB !23 	/JD$JJD83tf-.	/ 
h	

,S^,<DAB !23 	/JD$JJD83tf-.	/ 
l	"

-c*o->dCD*//+, 	#CJJC5z"	# 
g	

01(..0 	7LE5JJE!9IeW56	7 
r   c                  n   t        j                  d       t        j                  d       t        j                  d       t        j                  d       t        j                  d       t        j                  d       t        j                  d       t        j                  dt        t                      t        j                  d	t        t                      t        j                  d
t        t
                      t        j                  dt        t                      t        j                  dt        t                      t        j                  d       t        j                  d       t        j                  d       t        j                  d       t        j                  d       y)z(Show package information and statistics.z=
============================================================z)trendspyg - Google Trends Data Downloaderz<============================================================z
Version: 0.3.0zLicense: MITz.Homepage: https://github.com/flack0x/trendspygz
Supported Options:z  Countries:  z  US States:  z  Categories: z  Time Periods: z  Sort Options: z
Total Configurations: 188,000+z
Data Sources:z.  RSS:  Fast (0.2s), rich media, ~10-20 trendsz3  CSV:  Comprehensive (10s), filtered, ~360+ trendsN)r>   r?   r@   r   r   r   r   r	   r   r   r   inforz     s    
JJ}	JJ:;	JJv	JJ!#	JJ	JJ?A	JJ%'	JJI/01	JJI/01	JJJ012	JJ!#l"3!456	JJ!#l"3!456	JJ13	JJ"	JJ?A	JJDF	JJ}r   c                      t                y)zMain entry point for CLI.N)r   r   r   r   mainr|   3  s    Er   __main__)r   N)"__doc__rE   typingr   r>   ImportErrorprintrF   configr   r   r   r   r	   
downloaderr
   rss_downloaderr   groupversion_optionr   commandoptionChoicerb   re   boolrL   Pathr   rx   rz   r|   __name__r   r   r   <module>r      s     Q P 2 6 g=	 > 	 	4	 	:5	Q	 	%
 	,
 		%?	?? ? 	?
 ? 
? >?D 	4	 	.u	E	 	7	 	=e	T	 	)
 	l5	9	 		%B	BB B 	B
 B B B 
B \BJ 	DUZ	[	7C 7D 7 7<  *

 zF W	  	
:;	
45CHHQKs   J# #'KK