CoolFace
Apppublic

prashanth-criodo/SPARC

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
social_media_manager.cpython-312.pyc58 linesDownload Raw Back to __pycache__
1�

2[�g�����ddlZddlmZmZmZddlZejjd�Z3e4duZdZer	ddlZddlmZGd�d�Zy#e
$r
dZed�Y�"wxYw)	�N)�Dict�Optional�List�tweepyFzFailed to import tweepy)�ContentGeneratorc	�x�eZdZdefd�Zdedededefd�Zded	ed5efd�Zdded
ed6e	eeffd�Z7ded	ed8e	fd�Zy)�SocialMediaManager�
openai_clientc�D�||_d|_t|_d|_y)Ni)r9�twitter_char_limit�TWITTER_AVAILABLE�twitter_enabled�twitter_client)�selfr10s  �>/Users/prashanthkumar/SPARC/components/social_media_manager.py�__init__zSocialMediaManager.__init__s"��*���"%���0���"����api_key�11api_secret�access_token�access_token_secretc�<�|jstjd�y	tj||�}|j||�tj|�|_y#t$r+}tjdt|����Yd}~yd}~wwxYw)zInitialize Twitter API clientz>Twitter functionality is not available. Please install tweepy.FTz%Failed to initialize Twitter client: N)12r�st�errorr�OAuthHandler�set_access_token�APIr�	Exception�str)rrrrr�auth�es       r�setup_twitter_authz%SocialMediaManager.setup_twitter_auths����#�#��H�H�U�V��	��&�&�w�13�;�D��!�!�,�0C�D�"(�*�*�T�"2�D�����	��H�H�<�S��V�H�E�F���	�s�AA'�'	B�0!B�B�content�hashtags�returnc��d|j�ddj|��d|�d�}|jjdddid	d14|��}|d|jS)
z)Optimize content for Twitter using OpenAIz815        Rewrite the following content for Twitter (max z^ characters).16        Make it engaging and concise. Include these hashtags where appropriate: � z,17        18        Original content:19        �	20        zOptimize content for Twitter�role�Social Media Manager�Social Media Post�Conversational��
campaign_goal�persona�content_type�tone�
custom_promptN)r�joinr21�generate_content)rr#r$�prompt�responses     r�optimize_for_twitterz'SocialMediaManager.optimize_for_twitter-s���8�8<�8O�8O�7P�QQ�QT�QY�QY�Zb�Qc�Pd�e	�22�	�	����%�%�6�6�8��3�4�,�!� �7�23���0��0�0�1�1rN�subjectc��d|�d�}|jjdddidd|��}|s$|jd	�}td24�|D�d�}||d�S)
z%Format content for email using OpenAIz�25        Rewrite the following content as a professional email.26        Include a subject line, greeting, body, and signature.27        Make it engaging and professional.28        29        Original content:30        r(zFormat content for emailr)zEmail Marketing SpecialistzEmail Newsletter�Professionalr-�31c3�~K�|]5}|jd�r"|jdd�j����7y�w)zSubject:�N)�32startswith�replace�strip)�.0�lines  r�	<genexpr>z2SocialMediaManager.format_email.<locals>.<genexpr>Xs9����L�"�t���z�/J�!�L�L��R�8�>�>�@�L�s�;=zNew Campaign Update)r8�body)r33r4�split�next)rr#r8r5�
email_content�liness      r�format_emailzSocialMediaManager.format_emailAs���	�34�	�	�
���*�*�;�;�4��9�:�+�� �<�35�
��!�'�'��-�E��L�&+�L�.�0�G�36�!�37�	38rc	��	t|d�stjd�y|j||�}t	|�|j39kDrutjd�dt	|��d|j40�ddj|��d	|�d41�	}|jjddd
idd|��d|j42}tjd�tj|�tjd�5|jj|�}d|j��}ddddd�}tj j"j%|j||�d||d�cddd�S#1swYyxYw#t&$r�}dt)|�j+�vrtjd�n�dt)|�j+�vrtjd�nRdt)|�j+�vrtjd�n!tjd t)|����dt)|�d!�cYd}~Sd}~wwxYw)"zPost content to Twitterrz>Twitter client not initialized. Please check your credentials.Fz@Content exceeds Twitter's character limit. Optimizing further...z@43                The following content is too long for Twitter (z4 chars).44                Please shorten it to under zh characters while maintaining45                the key message. Include these hashtags if space permits: r'z;46                47                Content:48                z49                zShorten content for Twitterr)r*r+r,r-Nz)Posting the following content to Twitter:zPosting to Twitter...z https://twitter.com/user/status/rg)�impressions�clicks�conversions�roiT)�success�urlr#�	duplicatez0This content has already been posted to Twitter.�authenticationz=Twitter authentication failed. Please check your credentials.z50rate limitz3Twitter rate limit reached. Please try again later.zError posting to Twitter: )rOr)�hasattrrrr7�lenr�warningr3r51r4�info�code�spinnerr�
update_status�id�
session_state�analytics_manager�add_twitter_metricsrr�lower)	rr#r$�optimized_contentr5�tweet�	tweet_url�mock_metricsr!s	         r�post_to_twitterz"SocialMediaManager.post_to_twitteras<��9	7��4�!1�2����Y�Z�� $� 9� 9�'�8� L���$�%��(?�(?�?��52�53�]�^�@�@C�DU�@V�?W�X,�,0�,C�,C�+D�EK�KN�8�8�T\�K]�J^�_�#�#�$�
��%)�$6�$6�$G�$G�"?�#�%;�<�!4�)�"(�%H�%�+�4�*�*�
%,�!�
�G�G�?�@��G�G�%�&����3�4�
Y��+�+�9�9�:K�L��>�u�x�x�j�I�	�$%��#$��	 ��� � �2�2�F�F��H�H�%� ��$(�	�FW�X�#
Y�
Y�
Y��$�		7��c�!�f�l�l�n�,����K�L�!�S��V�\�\�^�3����X�Y���Q�����/����N�O����5�c�!�f�X�>�?�$�s�1�v�6�6��		7�sC�!F�CF�A,E8�.	F�8F�=F�F�	I�
CI�I�I)N)�__name__�54__module__�__qualname__rrrr"�listr7rrIrc�rrr	r	s���#�&6�#�
�#�
�3�
�c�
�hk�
�2�C�2�4�2�C�2�(55�C�56�#�57��c�3�h��58�@;7�s�;7�d�;7�t�;7rr	)�importlib.util�	importlib�typingrrr�	streamlitr�util�	find_spec�tweepy_specr
r�ImportError�print�utils.openai_helperrr	rhrr�<module>rssu���'�'���n�n�&�&�x�0���t�+��	
���)��1�E7�E7���)�!��
�'�(�)�s�A�A�A