
    cf                          d dl Z d dlZd dlZd dlmZ d dlmZmZ d dlm	Z	 d dl
Z
d dlZd dlZddlmZ  ej                    Zde_        d Zd	 Zd
 ZdS )    N)Bar)	timedeltadatetime)shuffle   )coreTc                 "   t          j        t                              | d                                                             }|                    dd          }t          |          dk    r|dd         dz   }| d         dd         d	|d
S )Ncontent
 2   r   z...
created_at
   z "")textwrapfillhhandlelstripreplacelen)statustexts     e/home/feoh/.local/pipx/venvs/mastodon-archive/lib/python3.11/site-packages/mastodon_archive/expire.pyr   r      s    =&"34455<<>>D<<c""D
4yy2~~AbDzE! .qt444ddd;;    c                    |dk    rR|d         r(|                      |d         d                    d|d<   dS |                     |d                    d|d<   dS |dk    r"|                     |d                    d|d<   dS dS )z
    Delete toot or unfavour favourite and mark it as deleted. The
    "record not found" error is handled elsewhere. Mentions cannot be
    dismissed because mastodon.notifications_dismiss requires a
    notification id, not a status id.
    statusesreblogidTdeleted
favouritesN)status_unreblogstatus_deletestatus_unfavourite)mastodon
collectionr   s      r   deleter'   &   s     Z( 	%$$VH%5d%;<<< $F9""6$<000 $F9	|	#	###F4L111 y 
$	#r   c                    | j         }| j        }| j        r5|dk    r/t          dt          j                   t	          j        d           | j                            d          \  }}|dz   |z   dz   t          j
        dd	          |rt          j        |           }nt          d
           t          | j                  }t          j                    |z
  fd}|dk    rQt!          t#          ||                             }t%          |          }	t'          |           |	dk    r't          d| d| j         dt          j                   |r||	dk    rut)          dt%          |                    }
d}fd}t+          j        t*          j        |           |D ]}	 t/          |||           # t0          $ r}dt3          |          v rIt          d           t          j        |            t          j        |           }t/          |||           nZdt3          |          v rd|d<   nCdt3          |          v rd}n/t          |t          j                   |
                                 Y d}~d}~ww xY w|
                                 |rt          |t          j                   t          j        | j                   nd|	dk    r^|D ][}|dk    r'| j        st          dt?          |          z              /|dk    r&| j        st          d t?          |          z              \|dk    rr| j        st          d!           n| j        st          d"           | j        st          j                     }t!          t#          d# |                             }| j        s.t%          |          }	t          d$t3          |	          z              d% |D             fd&}t          j!        |           }|"                    d'(          }d}d}d}|ry| j        s
 |             |t%          |          z  } ||          D ]1}|r	 |#                    |d)                    |d*z  }'# t0          $ r}dt3          |          v rXt          d           t          j        |            t          j        |           }|#                    |d)                    |d*z  }nAdt3          |          v rn/dt3          |          v rd}nt          |t          j                   Y d}~d}~ww xY wt          d+|d,         $                    d-          z   d.z   |d/         d0         z   d.z   |d1         z              3|%                    |          }|y|rt          |t          j                   | j        st          d2| d3| d4           dS dS dS )5zn
    Expire toots: delete toots, unfavour favourites, or dismiss
    notifications older than a few weeks
    mentionszPThe --delete-others option can only be used together with --collection mentions.)file   @z.user.z.jsonT)requiredquietzThis is a dry run and nothing will be expired.
Instead, we'll just list what would have happened.
Use --confirmed to actually do it.)weeksc                     t          j        | d         dd         d          }d| v o| d         dk    }d| v o| d         dk    }|k     o| o| S )Nr   r   r   %Y-%m-%dr    Tpinned)r   strptime)r   createdr    r2   cutoffs       r   matcheszexpire.<locals>.matchesW   sn    #F<$82$>
KKv%C&*;t*CV#@x(8D(@>K>J>r   r   zNo z are older than z weeksExpiring)max c                 x    t          d           t          j                   t          j        d           d S )Nz0
You pressed Ctrl+C! Saving data before exiting!r   )printr   savesysexit)signalframedatastatus_files     r   signal_handlerzexpire.<locals>.signal_handlerl   s5    IJJJ	+t,,,r   zauthorized scopesz>
We need to authorize the app to make changes to your account.z	not foundr    zName or service not knownz8Error: the instance name is either misspelled or offlineN)r.   r   zDelete: r!   z
Unfavour: z+Dismissing mentions and other notificationszDismissing mentionsc                 
    d| v S )Nr    )xs    r   <lambda>zexpire.<locals>.<lambda>   s
     r   zMentions already archived: c                      i | ]}|d          dS )r   TrE   ).0rF   s     r   
<dictcomp>zexpire.<locals>.<dictcomp>   s    111!$111r   c                 $    fd| D             S )Nc                     g | ];}|j         d k    r
|j        v r%nr"|d                             d          k     9|<S )mentionr   N)tzinfo)typer   r   )rI   rF   r5   delete_othersidss     r   
<listcomp>z+expire.<locals>.matches.<locals>.<listcomp>   sb     I I I!'(v':':,///>>GG GGGr   rE   )notificationsr5   rP   rQ   s    r   r6   zexpire.<locals>.matches   sA    I I I I I I} I I I Ir   d   )limitr   r   zDismiss r   r1   r   accountacctrO   z
Dismissed z of z notifications)&	confirmedr&   rP   r;   r=   stderrr>   usersplitr   load	readwriter   r/   r   todaylistfilterr   r   r   r?   SIGINTr'   	Exceptionstrdeauthorizenextfinishr<   r.   r   progress_barloginrS   notifications_dismissstrftime
fetch_next)argsrX   r&   usernamedomainr%   deltar6   r   
n_statusesbarerrorrC   r   eprogressrS   total	dismissednotificationr5   rA   rP   rQ   rB   s                       @@@@@r   expirerx   8   s    IJ&M *
22 5:	 	 	 	 	--Xv8#h.8K9[T4@@@D 4>$'' 3 	4 	4 	4 dj)))E^%F? ? ? ? ? ZwZ(899::]]
!OOF
FFDJFFFz# # # #  -	;ajH666CE     
 M&-888" # ##8Z8888  # # #*c!ff44_```(...#'>$#7#7xV<<<<$A..,0y))4A>> Zacj1111


# JJLLL .e#*----Ik4tz:::::!^^" ; ;++: 9j4<<7888<//: ;lT&\\9:::Z 	-: ECDDD: -+,,,z 	+(**H 22D4DEEFFz 	CXJ/#j//ABBB 21x111	I 	I 	I 	I 	I 	I 	I
 :d## ..S.99	 	?: 


S'''E ' 6 6 8 8 86 66|D7IJJJ!Q		$ 6 6 6.#a&&88!"cddd ,T222'+~d';';H$::<;MNNN%NII(CFF22 8CFFBB$^EE!!#*55556   ".|"<"E"Ej"Q"QR    #/y"9&"AB  	  #/v"6	7 8 8 8 8 %//>>M=  	?@  	*%cj))))z 	ECyCCeCCCDDDDDQ  N	E 	Es2   0G
J
B4JJ
" R
UB*T<<U)r=   os.pathosmathprogress.barr   r   r   randomr   r?   	html2textr   r9   r   	HTML2Textr   ignore_linksr   r'   rx   rE   r   r   <module>r      s   " 


         ( ( ( ( ( ( ( (                  I< < <! ! !$fE fE fE fE fEr   