
    "i                     8    d dl Z d dlZd dlmZ dZd Zd ZddZy)    N)datetimelogsc                     t         j                  j                  t              st        j                  t               t        j                         j                  d      } t         j                  j                  t        d|  d      S )u?   יוצר שם קובץ לוג לפי התאריך של היוםz%Y-%m-%dbot_log_.json)	ospathexistsLOG_DIRmakedirsr   nowstrftimejoin)todays    "/var/www/html/tradingbot/logger.pyget_daily_log_filer      sR    77>>'"
GLLN##J/E77<<8E7%!899    c                 8   t               }t        j                         j                  d      | d<   t        j
                  j                  |      s1t        |dd      5 }t        j                  | g|d       ddd       y	 t        |d	d      5 }t        j                  |      }ddd       j                  |        t        |dd      5 }t        j                  ||d       ddd       y# 1 sw Y   yxY w# 1 sw Y   VxY w#  g }Y _xY w# 1 sw Y   yxY w)
u'   שומר רשומה ללוג היומיz%Y-%m-%d %H:%M:%Stimestamp_readablewutf8)encoding   )indentNr)r   r   r   r   r   r	   r
   openjsondumploadappend)recordlog_filefdatas       r   
append_logr%      s    !#H $,<<>#:#:;N#OF 77>>(#(C&1 	-QIIvh!,	-(C&1 	 Q99Q<D	 
 	KK	hf	- %		$!$% %	-	  	 % %s<   C/D C;&D D/C8;D D DDc                 `   t         j                  j                  t              syt	        j
                         }t        j                  t              D ]  }|j                  d      s|j                  d      s't         j                  j                  t        |      }t	        j                  t         j                  j                  |            }||z
  j                  | kD  s	 t        j                  |       t        d|         y# t        $ r}t        d| d|        Y d}~d}~ww xY w)u3   מוחק לוגים ישנים (אופציונלי)Nr   r   u   🗑️ Deleted old log: zError deleting z: )r   r	   r
   r   r   r   listdir
startswithendswithr   fromtimestampgetmtimedaysremoveprint	Exception)days_to_keepr   filenamefilepath	file_timees         r   cleanup_old_logsr5   (   s    77>>'"
,,.CJJw' =z*x/@/@/Iww||GX6H ..rww/?/?/IJI i%%4=IIh'5hZ@A= ! =OH:Rs;<<=s   ##D			D-D((D-)   )r   r   r   r   r   r%   r5    r   r   <module>r8      s"     	 
:%0=r   