
    /j	                     b    d Z ddlZddlZddlmZ ddlmZ d Zd Zedk    r e             dS dS )zc
Cron job: Check for new order flow alerts and send to Telegram topic 2178.
Runs every 60 seconds.
    N)Path)datetimec                    	 d}ddd|d| g}t          j        |ddd          }|j        d	k    rt          d
           dS t          d|j                    dS # t
          $ r}t          d|            Y d}~dS d}~ww xY w)z<Send message to Telegram topic 2178 using send_message tool.ztelegram:SC Portal / topic 2178hermessend_messagez--targetz	--messageT   )capture_outputtexttimeoutr   u   ✅ Sent to Telegram topic 2178u   ❌ Failed: Fu   ❌ Error: N)
subprocessrun
returncodeprintstderr	Exception)messagetargetcmdresultes        Y/home/ubuntu/.hermes/workspace/projects/ORDER_FLOW_GRAPH/scripts/telegram_alert_sender.pysend_to_telegramr      s     3 	
 	
 
 
 !!455540001115   A   uuuuus   <A  A 
B #A;;B c                     t          d          } t          d          }|                                 sdS |                                 j        }t	          j                    }||z
  dk    rdS t          |           5 }|                                }ddd           n# 1 swxY w Y   |                                sdS |                                rbt          |          5 }|                                                                }||k    r	 ddd           dS 	 ddd           n# 1 swxY w Y   t          d           t          d           t          d           t          dt          j
                                        d                      t          d	           t          d
           t          |           t          d
           t          |          }|rMt          |d          5 }|                    |           ddd           n# 1 swxY w Y   t          d           nt          d           t          d           dS )z#Check for new alerts and send them.z/tmp/order_flow_alert.txtz/tmp/order_flow_alerts_sent.logNx   zP================================================================================zTELEGRAM ALERT SENDERu   
📊 z%Y-%m-%d %H:%M:%S UTCu&   
📱 Sending alert to topic 120949...zP--------------------------------------------------------------------------------wu   
✅ Alert sent successfully!u   
❌ Failed to send alert)r   existsstatst_mtimetimeopenreadstripr   r   nowstrftimer   write)
alert_filesent_logalert_mtimer#   fr   last_messagesuccesss           r   check_and_send_alertsr,   /   s    122J566H  //##,K
)++C [3 
j		 Q&&((               ==??   (^^ 	q6688>>++Lw&&		 	 	 	 	 	 	 	&	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 
&MMM	
!"""	&MMM	
FHLNN++,CDD
F
FGGG	
3444	&MMM	'NNN	&MMMw''G ,(C   	AGGG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	.////*+++	&MMMMMs6   ;BB #B  .D((D,/D,3HHH__main__)	__doc__r   r   pathlibr   r   r   r,   __name__     r   <module>r3      s    
                   D4 4 4n z r2   