Ë
    þ´j  ã            
       ó   — d Z ddlZddlZddlZddlmZmZ ddlmZ ddlm	Z	m
Z
mZmZmZ dedefd„Zddedz  defd	„Zdd
ededz  deeef   fd„Zedk(  r¨ ej*                  d¬«      Zej/                  dd¬«       ej/                  dd¬«       ej1                  «       Z e eej4                  «      ej6                  «      \  ZZ e ej>                  eed    e ed
   jC                  «       «      dœd¬«      «       yy)zLCreate an original, fast-paced story suited to a 45-65 second YouTube Short.é    N)ÚdatetimeÚtimezone)ÚOpenAI)ÚOPENAI_API_KEYÚOPENAI_BASE_URLÚOPENAI_MODELÚSTORIES_DIRÚSTORY_THEMESÚthemeÚreturnc                 ó   — d}d|dg d¢| ddœS )z>Works without an API key so the video renderer remains usable.aþ  My coworker kept stealing my lunch, and everyone told me I was imagining it. For three months, my meals disappeared from the fridge every Tuesday. So I put a tiny Bluetooth tracker inside a sealed container of leftovers. At noon, the signal led straight to our manager's office. He had been taking food because he thought nobody would confront him. I showed HR the location history, and suddenly he had a lot to explain. The next day, he brought in a whole tray of sandwiches for the team. Nobody touched them.z!My Manager Kept Stealing My LunchzPA workplace mystery with an unexpected ending. #storytime #redditstories #shorts)z#shortsz
#storytimez#redditstoriesz#karmazoriginal-fallback)ÚtitleÚstoryÚdescriptionÚhashtagsr   Úsource© )r   Útexts     ú!/root/workspace/ytshorts/story.pyÚfallback_storyr      s*   € ð	ð 	ð 5ØØiÚIØØ%ñð ó    c                 ó   ‡— | xs t        j                  t        «      } t        st	        | «      S t        t        t        ¬«      }d| › d�}	 |j                  j                  j                  t        d|dœgdddi¬	«      }t        j                  |j                  d
   j                  j                  «      Št!        ˆfd„dD «       «      st#        d«      ‚| ‰d<   d‰d<   ‰S # t$        $ r$}t'        d|› d�«       t	        | «      cY d }~S d }~ww xY w)N)Úapi_keyÚbase_urlzAWrite an original first-person story for a YouTube Short.
Theme: a~  

Rules:
- 125 to 150 spoken English words, target 50 to 60 seconds.
- Begin with a compelling hook in the first sentence.
- Use natural spoken language, short sentences, and escalating stakes.
- End with a satisfying, surprising, or ironic payoff.
- Entirely fictional and original. Do not reference Reddit, real people, brands, or existing posts.
- No graphic violence, sexual content, self-harm, hate, or slurs.

Return ONLY valid JSON matching this shape:
{"title":"under 65 characters", "story":"the narration text", "description":"under 150 characters, includes 2-4 relevant hashtags", "hashtags":["#shorts", "#storytime", "#... "]}Úuser)ÚroleÚcontentg      ð?ÚtypeÚjson_object)ÚmodelÚmessagesÚtemperatureÚresponse_formatr   c              3   ó@   •K  — | ]  }‰j                  |«      –— Œ y ­w©N)Úget)Ú.0Úkr   s     €r   ú	<genexpr>z!generate_story.<locals>.<genexpr>=   s   øè ø€ ÒW A�5—9‘9˜Q—<ÑWùs   ƒ)r   r   r   r   z&Model response omitted required fieldsr   zoriginal-air   zStory API failed (z"); using the local fallback story.)ÚrandomÚchoicer
   r   r   r   r   ÚchatÚcompletionsÚcreater   ÚjsonÚloadsÚchoicesÚmessager   ÚallÚ
ValueErrorÚ	ExceptionÚprint)r   ÚclientÚpromptÚresponseÚexcr   s        @r   Úgenerate_storyr;   "   s  ø€ ØÒ0”V—]‘]¤<Ó0€EÝÜ˜eÓ$Ð$äœN´_ÔE€FðØ€wð uðx€Fð%Ø—;‘;×*Ñ*×1Ñ1ÜØ%°&Ñ9Ð:ØØ# ]Ð3ð	 2ó 
ˆô —
‘
˜8×+Ñ+¨AÑ.×6Ñ6×>Ñ>Ó?ˆÜÓWÐ)VÔWÔWÜÐEÓFÐFØˆˆg‰Ø'ˆˆh‰ØˆøÜò %ÜÐ" 3 %Ð'IÐJÔKÜ˜eÓ$Õ$ûð%ús   ÁBC  Ã 	DÃ)DÄDÄDr   Ústemc                 óN  — t        j                  t        j                  «      j	                  d«      }|xs |}t        j                  t        j                  «      j                  «       | d<   t        |› d�z  }|j                  t        j                  | dd¬«      dz   «       | |fS )Nz%Y%m%d_%H%M%SÚ
created_atz.jsoné   T)ÚindentÚensure_asciiú
)
r   Únowr   ÚutcÚstrftimeÚ	isoformatr	   Ú
write_textr/   Údumps)r   r<   Ú	timestampÚpaths       r   Ú
save_storyrK   G   s�   € Ü—‘œXŸ\™\Ó*×3Ñ3°OÓD€IØÒ�9€DÜ"Ÿ,™,¤x§|¡|Ó4×>Ñ>Ó@€Eˆ,ÑÜ˜D˜6 ˜Ñ'€DØ‡O�O”D—J‘J˜u¨Q¸TÔBÀTÑIÔJØ�$ˆ;Ðr   Ú__main__z Generate an original Short story)r   z--themezStory theme)Úhelpz--output-stemzOutput filename stemr   )r<   r   Úwordsr?   )r@   r%   )"Ú__doc__Úargparser/   r*   r   r   Úopenair   Úconfigr   r   r   r	   r
   ÚstrÚdictr   r;   ÚtuplerK   Ú__name__ÚArgumentParserÚparserÚadd_argumentÚ
parse_argsÚargsr   Úoutput_stemr   r<   r6   rH   ÚlenÚsplitr   r   r   ú<module>r_      s  ðÙ RÛ Û Û ß 'å ç [Õ [ð˜#ð  $ó ñ,"%˜# ™*ð "%°ó "%ñJ�dð  #¨¡*ð ¸¸dÀC¸iÑ8Hó ð ˆzÒØ$ˆX×$Ñ$Ð1SÔT€FØ
×Ñ˜	¨ÐÔ6Ø
×Ñ˜Ð.DÐÔEØ×ÑÓ€DÙ™^¨D¯J©JÓ7¸×9IÑ9IÓJ�K€Eˆ4Ù	ˆ*ˆ$�*‰*˜d¨U°7©^ÁcÈ%ÐPWÉ.×J^ÑJ^ÓJ`ÓFaÑbÐklÔ
mÕnð r   