1
+ from pip import main
2
+ import argparse
3
+ from anilist_tools .upcoming_sequels import get_user_id_by_name
4
+ from anilist_tools .utils import depaginated_request
5
+
6
+ STATUSES = ['CURRENT' , 'PLANNING' , 'COMPLETED' , 'DROPPED' , 'PAUSED' , 'REPEATING' ]
7
+
8
+ def get_user_media (user_id , status = 'COMPLETED' , type = 'ANIME' ):
9
+ """Given an AniList user ID, fetch the user's anime list, returning a list of shows and details."""
10
+ query = '''
11
+ query ($userId: Int, $type: MediaType, $status: MediaListStatus, $page: Int, $perPage: Int) {
12
+ Page (page: $page, perPage: $perPage) {
13
+ pageInfo {
14
+ hasNextPage
15
+ }
16
+ # Note that a MediaList object is actually a single list entry, hence the need for pagination
17
+ mediaList(userId: $userId, type: $type, status: $status, sort: SCORE_DESC) {
18
+ media {
19
+ id
20
+ title {
21
+ english
22
+ romaji
23
+ }
24
+ type
25
+ format
26
+ episodes
27
+ }
28
+ score
29
+ status
30
+ progress
31
+ repeat
32
+ startedAt {
33
+ year
34
+ month
35
+ day
36
+ }
37
+ completedAt {
38
+ year
39
+ month
40
+ day
41
+ }
42
+ updatedAt
43
+ notes
44
+ hiddenFromStatusLists
45
+ customLists
46
+ }
47
+ }
48
+ }'''
49
+
50
+ return [list_entry for list_entry in depaginated_request (query = query ,
51
+ variables = {'userId' : user_id , 'type' : type , 'status' : status })]
52
+
53
+ def main (username : str ):
54
+ user_id = get_user_id_by_name (username )
55
+ user_media_list = get_user_media (user_id )
56
+ for entry in user_media_list :
57
+ print (entry )
58
+
59
+ if __name__ == "__main__" :
60
+ parser = argparse .ArgumentParser (
61
+ description = "Given an anilist username, print all the shows they have completed on Anilist." ,
62
+ formatter_class = argparse .RawTextHelpFormatter ) # Preserves newlines in help text
63
+ parser .add_argument ('-u' , '--username' , required = False , default = 'mannerpots' ,
64
+ help = "User whose list should be checked." )
65
+ args = parser .parse_args ()
66
+
67
+ main (args .username )
0 commit comments