
    cf.                     4    d dl Z d dlZddlmZ d dlmZ d ZdS )    N   )core)MastodonAPIErrorc                    !"  j         } j        } j        } j        } j        } j        } j        } j        } j        "t          j
         j                  \  }	}
|
dz   |	z   dz   }t          j        | j                  }t          j                   ! j        st          d           	 !                                }n# t"          $ r}dt%          |          v r8t          j                    t)                      t+          j        d           nHdt%          |          v rt          dt*          j        	           nt          |t*          j        	           t+          j        d
           Y d}~nd}~ww xY wd< !"fd	}d }|d|vst1          |d                   dk    rJ j        st          d           !                    |d         d          }!                    |          }nC j        st          d            ||d         !                    |d         d                    }|r( j        st          d           |d|vrg }n|d         }n|d|vst1          |d                   dk    rA j        st          d           !                                }!                    |          }n: j        st          d            ||d         !                                          }	 |r( j        st          d           |d|vrg }n|d         }n|d|vst1          |d                   dk    rA j        st          d           !                                }!                    |          }n: j        st          d            ||d         !                                          }ns# t:          $ rf}g }t          d           t          d           t          d           t          d            t          d!           t          d"           Y d}~nd}~ww xY w|s( j        st          d#           |d$|vrg }n|d$         }n|d$|vst1          |d$                   dk    rN j        st          d%           !                    d          }!                    |          } ||          }n@ j        st          d&           d' } ||d$         !                    d          |          }|s( j        st          d(           |d)|vrg }nQ|d)         }nH j        st          d*           !                    |j         d          }!                    |          }|s( j        st          d+           |d,|vrg }nQ|d,         }nH j        st          d-           !!                    |j         d          }!                    |          }|s( j        st          d.           |d/|vrg }nK|d/         }nB j        st          d0           !"                    d          }!                    |          }|s( j        st          d1           |d2|vrg }nK|d2         }nB j        st          d3           !#                    d          }!                    |          }|s* j        st          d4           |d5|vrg }n|d5         }n j        st          d6           tI                      }||||fD ]"}|D ]}|%                    |d                    #tM          |          }d}g }t1          |          }|t1          |          k     r	 !'                    ||||z                      } n3# tP          $ r&}d7|j)        v rtU          |d8z            }Y d}~_ d}~ww xY w||z  }|+                    d9 | D                        |t1          |          k     ||||||||||d:
} j        st          d;t1          |          t1          |          t1          |          t1          |          t1          |          t1          |          t1          |          t1          |          t1          |          f	z             t          j,        || j                   dS )=zR
    Archive your toots, favourites, and bookmarks from your Mastodon account
    z.user.z.json)quietzGet user infozaccess token was revokedr   zName or service not knownz8Error: the instance name is either misspelled or offline)filer   Nc                      d  D             j         st          j                     	fd} ||          }j         st          d|z              S )u  
        Why aren't we using Mastodon.fetch_remaining(first_page)? It
        requires some metadata for the next request to be known. This
        is what the documentation says about
        Mastodon.fetch_next(previous_page): "Pass in the previous page
        in its entirety, or the pagination information dict returned
        as a part of that pages last status (‘_pagination_next’)."
        When we last updated our archive, however, there was no next
        page: we got all the pages there were. So the archive will
        have a ton of _pagination_prev keys but no _pagination_next
        keys. That's why we fetch it all over again. Expiry helps,
        obviously.
        c                 >    i | ]}|t          |d                   |S )Nid)str).0statuss     f/home/feoh/.local/pipx/venvs/mastodon-archive/lib/python3.11/site-packages/mastodon_archive/archive.py
<dictcomp>z-archive.<locals>.complete.<locals>.<dictcomp>M   s+    YYYvVEWVD\""FEWEWEW    c                 "   d}d}t          |           dk    rj        s
 	             | D ]}|}d|v r|d         }|rd|v rt          |d                   }|
vr. |          r |
d<                       ||           |dz   }]|dz   }|dk    r9r7j        s,t	                       t	          d           t	          d           |c S                     |           } | j        st	                       |S t          |           dk    |S )Nr   r   r   r   
   z!Seen 10 duplicates, stopping now.z"Use --no-stopping to prevent this.)lenr   r   insertprint
fetch_next)pagecount
duplicatesitemr   r   argsfuncmastodonprogressseenstatusesstoppings         r   processz*archive.<locals>.complete.<locals>.processS   sU   EJd))a--z HJJJ  - -D!F4''!%h -$&.. ..!Tzz#|ttDzz|-3T
 (v > > >(-	)3aJ)B8'+z !P$)GGG$)*M$N$N$N$)*N$O$O$O',**400<:   L7 d))a--: Lr   zAdded a total of %d new items)r   r   progress_barr   )
r!   r   r   r#   r   r   r    r   r   r"   s
   ` `  @@r   completezarchive.<locals>.complete?   s     ZYYYYz 	+(**H 	  	  	  	  	  	  	  	  	  	  	D z 	;1E9:::r   c                     d | D             S )Nc                 2    g | ]}|j         d k    |j        S )mention)typer   )r   xs     r   
<listcomp>z2archive.<locals>.keep_mentions.<locals>.<listcomp>{   s&    GGGQ16Y3F3F3F3F3Fr    )notificationss    r   keep_mentionszarchive.<locals>.keep_mentionsz   s    GG-GGGGr   r!   z(Get all statuses (this may take a while)r   d   )limit)
first_pagezGet new statuseszSkipping favourites
favouritesz&Get favourites (this may take a while)zGet new favouriteszSkipping bookmarks	bookmarksz%Get bookmarks (this may take a while)zGet new bookmarksz=Skipping bookmarks since your Mastodon.py library is too old!zGYou might have a file called upgrade_python-mastodon.sh on your system.zMFind it for example using 'locate upgrade_python-mastodon.sh' and then run itzJto attempt an upgrade in-place: 'bash /path/to/upgrade_python-mastodon.sh'zKIf you don't have 'locate' installed, try to use 'find' to find the script:z)'find / -name upgrade_python-mastodon.sh'zSkipping mentionsmentionsz?Get notifications and look for mentions (this may take a while)z+Get new notifications and look for mentionsc                 "    d| v o| d         dk    S )Nr)   r(   r,   )r*   s    r   <lambda>zarchive.<locals>.<lambda>   s    v{EqyI/E r   zSkipping followers	followersz%Get followers (this may take a while)zSkipping following	followingz%Get following (this may take a while)zSkipping mutesmutesz!Get mutes (this may take a while)zSkipping blocksblocksz"Get blocks (this may take a while)zSkipping notesnotesz!Get notes (this may take a while)i     c              3   B   K   | ]}|j         	|j        |j         d V  dS ))r   noteN)r>   r   )r   us     r   	<genexpr>zarchive.<locals>.<genexpr>  sH       < <AF<qv66 < < < < < <r   )
accountr!   r2   r3   r4   r7   r8   r9   r:   r;   zwSaving %d statuses, %d favourites, %d bookmarks, %d mentions, %d followers, %d following, %d mutes, %d blocks, %d notes)N)-skip_favouritesskip_bookmarkswith_mentionswith_followerswith_following
with_muteswith_blocks
with_notesr"   r   parseuserloadr   loginr   account_verify_credentials	Exceptionr   deauthorizearchivesysexitstderrr   account_statusesfetch_remainingr2   r3   AttributeErrorr-   account_followersr   account_followingr9   r:   setaddlistaccount_relationshipsr   r   intextendsave)#r   rB   rC   rD   rE   rF   rG   rH   rI   usernamedomainstatus_filedatarK   er%   r.   r!   r2   r3   r4   r-   
is_mentionr7   r8   r9   r:   r;   all_idscoll	requestedrequest_sizerelationshipsr   r"   s#   `                                @@r   rQ   rQ      s
   
 *O(N&M(N(NJ"KJ}HDI..Xv8#h.8K9[$*555Dz$H: o2244   %Q//T"""DMMMHQKKKK(CFF22L:     !#*%%%%9 9 9 9 9 9 9 9vH H H |:--T*5E1F1F!1K1Kz 	><===,,T$Zs,CC++! , # # z 	&$%%%8D,h.G.GT
Z].G.^.^__ Iz 	)'(((<|t33JJl+JJ	\T11Sl9K5L5LPQ5Q5Qz 	<:;;;((**
--# . % %

 z 	(&'''Xd<0(2E2E2G2GHH
; 	J: ,*+++|;$#6#6		 -		\!4!4D<M8N8NRS8S8S: ?=>>> **,,I 00& 1 ( (II : +)*** k!2H4F4F4H4HIII ; ; ;	MNNNWXXX]^^^Z[[[[\\\9::::::::;  ]z 	'%&&&<zT11HHJ'HH	Z4//3tJ7G3H3HA3M3Mz 	USTTT ..S.99 00& 1 ( ( =//z 	A?@@@EE
8D,h.D.D3.D.O.OQ[\\ $z 	(&'''<{d22II[)IIz 	;9:::..twc.BB	,," - $ $	  $z 	(&'''<{d22II[)IIz 	;9:::..twc.BB	,," - $ $	  =z 	$"###<w$EEMEEz 	75666S))((e(<< ?z 	%#$$$<x4//FF(^FFz 	86777s++))v)>> =z 	$"###<w$EEMEEz 	75666%%	5&9 	( 	(D ( (DJ''''(w-- 	7||#g,,&& ( > >Ii,&>>?!A !A#   !&==#&|a'7#8#8LHHHH	
 %ILL < <#0< < < = = = #g,,&&   D : 
  HMM
OO	NNMM	NN	NNJJKKJJ	K 	 		 		 		 	Ik4tz222222sQ   0C 
E>B%E99E>=CO 
P2AP--P27 ^ 
_"___)rR   os.pathos r   mastodon.errorsr   rQ   r,   r   r   <module>rp      s[   " 


        , , , , , ,c3 c3 c3 c3 c3r   