-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
trim_list.py
209 lines (191 loc) · 8.29 KB
/
trim_list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# Remove Entries that have MAL ID
# And additional code to get stats
# imports
import os
import json
# Local imports
import func.main as fMain
# Other vars
logSrc = "trim_list"
fMain.logString("Imported func.trim_list", "")
# Functions
def sort_byval(json):
try:
return str(json['format'])
except KeyError:
return ""
def trim_results(filepath, inputAnime, inputManga, isNsfw):
# Declare filepaths
if isNsfw:
outputStats = os.path.join(filepath, "output", f'nsfw_animemanga_stats.txt')
else:
outputStats = os.path.join(filepath, "output", f'animemanga_stats.txt')
outputAnime = f'{inputAnime[:-5]}_NotInMAL.json'
outputManga = f'{inputManga[:-5]}_NotInMAL.json'
# STATS variables
statScoreTotal = 0
statScoreCount = 0
statInMAL = 0
# Count entries
cTotal = 0
cCurrent = 0
cComplete = 0
cHold = 0
cDrop = 0
cPlan = 0
# Delete prev files
fMain.deleteFile(outputStats)
# Load JSON objects
# Check if anime file Exists!
if not (os.path.exists(inputAnime)):
fMain.logString("Anime json file does not exists!", logSrc)
jsonAnime = None
else:
fMain.logString("Loading " + os.path.basename(inputAnime) + " into memory..", logSrc)
with open(inputAnime, "r+", encoding='utf-8') as F:
jsonAnime = json.load(F)
jsonAnime.sort(key=sort_byval, reverse=True)
fMain.logString("Anime json file loaded!", logSrc)
# Check if manga file Exists!
if not (os.path.exists(inputManga)):
fMain.logString("Manga json file does not exists!", logSrc)
jsonManga = None
else:
fMain.logString("Loading " + os.path.basename(inputManga) + " into memory..", logSrc)
with open(inputManga, "r+", encoding='utf-8') as F:
jsonManga = json.load(F)
jsonManga.sort(key=sort_byval, reverse=True)
fMain.logString("Manga json file loaded!", logSrc)
# json Objects
jsonOutputAnime = []
jsonOutputManga = []
# Get entries from Anime, not in MAL
if jsonAnime is not None:
fMain.logString("Checking anime list..", logSrc)
for entry in jsonAnime:
# Get each entry
if (entry["idMal"] < 1):
# If not in MAL, ID = 0
statInMAL += 1
jsonData = {}
jsonData["idAnilist"] = entry["idAnilist"]
jsonData["titleEnglish"] = entry["titleEnglish"]
jsonData["titleRomaji"] = entry["titleRomaji"]
if str(entry["synonyms"]) == "[]":
jsonData["synonyms"] = ""
else:
jsonData["synonyms"] = entry["synonyms"]
jsonData["format"] = entry["format"]
jsonData["source"] = entry["source"]
jsonData["status"] = entry["status"]
jsonData["startedAt"] = entry["startedAt"]
jsonData["completedAt"] = entry["completedAt"]
jsonData["progress"] = entry["progress"]
jsonData["totalEpisodes"] = entry["totalEpisodes"]
jsonData["score"] = entry["score"]
jsonData["notes"] = entry["notes"]
# Append to JSON object
jsonOutputAnime.append(jsonData)
# Stats checker
statScore = int(entry["score"])
if (statScore > 0):
statScoreTotal = statScoreTotal + statScore
statScoreCount = statScoreCount + 1
# Count entries
AnilistStatus = str(entry["status"])
if (AnilistStatus == "COMPLETED"):
cComplete = cComplete + 1
elif (AnilistStatus == "PAUSED"):
cHold = cHold + 1
elif (AnilistStatus == "CURRENT"):
cCurrent = cCurrent + 1
elif (AnilistStatus == "DROPPED"):
cDrop = cDrop + 1
elif (AnilistStatus == "PLANNING"):
cPlan = cPlan + 1
elif (AnilistStatus == "REPEATING"):
cCurrent = cCurrent + 1
# Write 'outputAnime'
if jsonOutputAnime:
fMain.createJsonFile(outputAnime, jsonOutputAnime, logSrc)
# Write stats for Anime
cTotal = cComplete + cCurrent + cHold + cPlan + cDrop
fMain.logString("Appending to file (Average Score stats): " + os.path.basename(outputStats), logSrc)
averageScore = "{:.2f}".format(statScoreTotal/statScoreCount * 10)
fMain.write_append(outputStats, "Anime stats:\nAverage Score (out of 100): " + averageScore + "\n")
fMain.write_append(outputStats, "Count:\nCompleted: " + str(cComplete) + "\nCurrently Watching: " + str(cCurrent) + "\nPaused: " + str(cHold) + "\nPlanning: " + str(cPlan) + "\nDropped: " + str(cDrop) + "\n")
fMain.write_append(outputStats, "\nTotal: " + str(cTotal))
fMain.write_append(outputStats, "\nAnime Not in MAL: " + str(statInMAL) + "\n")
# Add Line Break
fMain.write_append(outputStats, "=========================================\n")
# Reset vars
statScoreTotal = 0
statScoreCount = 0
statInMAL = 0
# Reset count
cTotal = 0
cCurrent = 0
cComplete = 0
cHold = 0
cDrop = 0
cPlan = 0
# For MANGA
# Get entries from MANGA, not in MAL
if jsonManga is not None:
fMain.logString("Checking manga list..", logSrc)
for entry in jsonManga:
# Get each entry
if (entry["idMal"] < 1):
# If not in MAL, ID = 0
statInMAL += 1
jsonData = {}
jsonData["idAnilist"] = entry["idAnilist"]
jsonData["titleEnglish"] = entry["titleEnglish"]
jsonData["titleRomaji"] = entry["titleRomaji"]
if str(entry["synonyms"]) == "[]":
jsonData["synonyms"] = ""
else:
jsonData["synonyms"] = entry["synonyms"]
jsonData["format"] = entry["format"]
jsonData["source"] = entry["source"]
jsonData["status"] = entry["status"]
jsonData["startedAt"] = entry["startedAt"]
jsonData["completedAt"] = entry["completedAt"]
jsonData["progress"] = entry["progress"]
jsonData["progressVolumes"] = entry["progressVolumes"]
jsonData["totalChapters"] = entry["totalChapters"]
jsonData["totalVol"] = entry["totalVol"]
jsonData["score"] = entry["score"]
jsonData["notes"] = entry["notes"]
# Append to JSON object
jsonOutputManga.append(jsonData)
# Stats checker
statScore = int(entry["score"])
if (statScore > 0):
statScoreTotal = statScoreTotal + statScore
statScoreCount = statScoreCount + 1
# Count entries
AnilistStatus = str(entry["status"])
if (AnilistStatus == "COMPLETED"):
cComplete = cComplete + 1
elif (AnilistStatus == "PAUSED"):
cHold = cHold + 1
elif (AnilistStatus == "CURRENT"):
cCurrent = cCurrent + 1
elif (AnilistStatus == "DROPPED"):
cDrop = cDrop + 1
elif (AnilistStatus == "PLANNING"):
cPlan = cPlan + 1
elif (AnilistStatus == "REPEATING"):
cCurrent = cCurrent + 1
# Write 'outputManga'
if jsonOutputManga:
fMain.createJsonFile(outputManga, jsonOutputManga, logSrc)
# Write stats for Manga
cTotal = cComplete + cCurrent + cHold + cPlan + cDrop
fMain.logString("Appending to file (Average Score stats): " + os.path.basename(outputStats), logSrc)
averageScore = "{:.2f}".format(statScoreTotal/statScoreCount * 10)
fMain.write_append(outputStats, "Manga stats:\nAverage Score (out of 100): " + averageScore + "\n")
fMain.write_append(outputStats, "Count:\nCompleted: " + str(cComplete) + "\nCurrently Reading: " + str(cCurrent) + "\nPaused: " + str(cHold) + "\nPlanning: " + str(cPlan) + "\nDropped: " + str(cDrop) + "\n")
fMain.write_append(outputStats, "\nTotal: " + str(cTotal))
fMain.write_append(outputStats, "\nManga Not in MAL: " + str(statInMAL) + "\n")