Skip to content

Commit 8231bbb

Browse files
author
Anonymous
committed
Make parser adjustments to allow prettify and adds missing newline
1 parent e0f873d commit 8231bbb

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

altSourceParser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def combineSourcesV1(fileName: str, primarySource: dict, sourcesData: list, alte
6565
json.dump(primarySource, file)
6666
print(primarySource["name"] + " successfully updated.")
6767

68-
def combineSources(fileName: str, sourcesData: list, alternateAppData: dict = None):
68+
def combineSources(fileName: str, sourcesData: list, alternateAppData: dict = None, prettify: bool = False):
6969
primarySource: dict = {}
7070
with open(fileName, "r") as file:
7171
primarySource = json.load(file)
@@ -101,11 +101,11 @@ def combineSources(fileName: str, sourcesData: list, alternateAppData: dict = No
101101
primarySource["news"].append(article)
102102

103103
except Exception as e:
104-
raise(e)
105104
print("Error parsing source: " + data["url"] + "\n" + str(e) + "\nUpdates to this source will not be processed.")
106105
continue
107106

108107
# Should probably do some evaluating to see if there were actually any changes made.
109108
with open(fileName, "w") as file:
110-
json.dump(primarySource, file)
109+
json.dump(primarySource, file, indent = 2 if prettify else None)
110+
file.write("\n") # add missing newline to EOF
111111
print(primarySource["name"] + " successfully updated.")

0 commit comments

Comments
 (0)