Ë
    JFjï	  ã                  ó~   — d Z ddlmZ ddlZddlmZ ddlmZ ddl	m
Z
mZ ddlmZ  ej                  e«      Zd	d
d„Zy)zUTrack B: refresh trending topics via Anthropic (niche research, not blog URL scrape).é    )ÚannotationsN)Úsettings)Útimezone)ÚBlogArticleÚBlogSettings)Úclaude_jsonc           	     ó:  — | xs t        j                  «       } | j                  xs dj                  «       }|st	        d«      ‚t        t        j                  j                  d¬«      j                  dd«      d d «      }dj                  d„ |D «       «      xs d	}t        t        d
d«      }| j                  xs d}| j                  xs d}| j                  xs d}d|› d|› d�}d|› d|xs d› d|› d|› d�	}		 t!        ||	d¬«      }
|
d | | _        t%        j&                  «       | _        d| _        | j-                  g d¢¬«       | j"                  S # t.        $ r?}t0        j3                  d«       t5        |«      | _        | j-                  ddg¬«       ‚ d }~ww xY w)NÚ z3description is required for trending topic research)Útitler   Útarget_keywordé   z, c              3  ó6   K  — | ]  \  }}|sŒ	|› d |› �–— Œ y­w)Ú/N© )Ú.0ÚtÚks      úC/var/www/html/shopify_to_digistore/blogs/services/trends_service.pyÚ	<genexpr>z*refresh_trending_topics.<locals>.<genexpr>   s!   è ø€ Ð>©y¡t q¨!ºA˜1˜#˜Q˜q˜cœ
©yùs   ‚
�ÚnoneÚBLOG_TRENDING_TOPICS_MAXé   ÚdeÚStorez$You are an SEO trend researcher for z. Language/market: uè   . Return ONLY a JSON array of objects with: keyword, title_hint, relevance_score (0-1 number), reason (one sentence). Topics must be timely search/blog opportunities for this niche â€” not a list of what one store already published.zNiche / store description:
z

Target audience: ÚgeneralzC
In-app articles already planned (avoid duplicating these angles): z


Propose z< trending blog topic opportunities for this niche right now.g333333ã?)Útemperature)Útrending_topicsÚtrending_topics_updated_atÚtrending_topics_errorÚ
updated_at)Úupdate_fieldsztrending topics refresh failedr   r    )r   ÚloadÚdescriptionÚstripÚ
ValueErrorÚlistr   ÚobjectsÚexcludeÚvalues_listÚjoinÚgetattrÚdjango_settingsÚlanguageÚ
store_nameÚtarget_audiencer   r   r   Únowr   r   ÚsaveÚ	ExceptionÚloggerÚ	exceptionÚstr)Úsettings_objr#   Ú	db_titlesÚdb_hintÚ
max_topicsÚlangÚstoreÚaudienceÚsystemÚuserÚtopicsÚexcs               r   Úrefresh_trending_topicsrA      sÑ  € ØÒ6¤<×#4Ñ#4Ó#6€LØ×+Ñ+Ò1¨r×8Ñ8Ó:€KÙÜÐNÓOÐOäÜ×Ñ×#Ñ#¨"Ð#Ó-×9Ñ9¸'ÐCSÓTÐUXÐVXÐYó€Ið �i‰iÑ>©yÓ>Ó>ÒHÀ&€GäœÐ*DÀbÓI€JØ× Ñ Ò( D€DØ×#Ñ#Ò. w€EØ×+Ñ+Ò1¨r€Hð /¨u¨gð 6Ø ˜6ð ":ð	:ð ð ' { mð 4Ø$Ò1¨	Ð2ð 3MØMTÈIð VØ�,ÐZð	\ð 	ðÜ˜V T°sÔ;ˆØ'-¨k¨zÐ':ˆÔ$Ü2:·,±,³.ˆÔ/Ø-/ˆÔ*Ø×Ñòð 	ô 	
ð ×+Ñ+Ð+øÜò Ü×ÑÐ9Ô:Ü-0°«XˆÔ*Ø×ÑÐ)@À,Ð(OÐÔPØûð	ús   Ã:AE Å	FÅ:FÆF)N)r6   zBlogSettings | NoneÚreturnz
list[dict])Ú__doc__Ú
__future__r   ÚloggingÚdjango.confr   r,   Údjango.utilsr   Úblogs.modelsr   r   Úblogs.services.anthropic_utilsr   Ú	getLoggerÚ__name__r3   rA   r   ó    r   Ú<module>rM      s1   ðÙ [å "ã å 3Ý !ç 2Ý 6à	ˆ×	Ñ	˜8Ó	$€õ1rL   