Skip to content

Commit

Permalink
func: main, trim_list: Create method to dump json object to json file
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacekun committed May 27, 2021
1 parent 50e45a6 commit 2367e9b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
11 changes: 10 additions & 1 deletion func/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,13 @@ def dumpToJson(objToDump, filePath):
F.write(json.dumps(objToDump, ensure_ascii=True, indent=4).encode('utf8').decode())
return True
except:
return False
return False

def createJsonFile(filepath, jsonObject, logSrc = "main"):
logString("Writing to file " + os.path.basename(filepath), logSrc)
try:
with open(filepath, "w+", encoding='utf-8') as F:
F.write(json.dumps(jsonObject, ensure_ascii=False, indent=4).encode('utf8').decode())
logString("File generated: " + filepath, logSrc)
except:
logString(f"Cannot write json file: {filepath}", logSrc)
10 changes: 2 additions & 8 deletions func/trim_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@ def trim_results(filepath, inputAnime, inputManga):

# Write 'outputAnime'
if jsonOutputAnime:
fMain.logString("Writing to file " + os.path.basename(outputAnime), logSrc)
with open(outputAnime, "w+", encoding='utf-8') as F:
F.write(json.dumps(jsonOutputAnime, ensure_ascii=False, indent=4).encode('utf8').decode())
fMain.logString("File generated: " + outputAnime, logSrc)
fMain.createJsonFile(outputAnime, jsonOutputAnime, logSrc)

# Write stats for Anime
cTotal = cComplete + cCurrent + cHold + cPlan + cDrop
Expand Down Expand Up @@ -196,10 +193,7 @@ def trim_results(filepath, inputAnime, inputManga):

# Write 'outputManga'
if jsonOutputManga:
fMain.logString("Writing to file " + os.path.basename(outputManga), logSrc)
with open(outputManga, "w+", encoding='utf-8') as F:
F.write(json.dumps(jsonOutputManga, ensure_ascii=False, indent=4).encode('utf8').decode())
fMain.logString("File generated: " + outputManga, logSrc)
fMain.createJsonFile(outputManga, jsonOutputManga, logSrc)

# Write stats for Manga
cTotal = cComplete + cCurrent + cHold + cPlan + cDrop
Expand Down

0 comments on commit 2367e9b

Please sign in to comment.