Skip to content

Commit

Permalink
Indent split JSON files
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusShepherd committed Aug 23, 2024
1 parent dae4f59 commit db8c5ff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions board_game_scraper/news.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def update_news(
path_out=path_split,
size=split_size,
exclude_empty=True,
indent=4,
dry_run=dry_run,
)

Expand Down
6 changes: 4 additions & 2 deletions board_game_scraper/split.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sys

from pathlib import Path
from typing import Optional, Union

from pytility import batchify
from scrapy.utils.misc import arg_to_iter
Expand Down Expand Up @@ -79,6 +80,7 @@ def split_files(
size=None,
fields=FIELDS,
exclude_empty=False,
indent: Optional[int] = None,
dry_run: bool = False,
):
"""Split a JSON lines file into JSON files of a given size."""
Expand Down Expand Up @@ -116,15 +118,15 @@ def split_files(
}

if path_out == "-":
json.dump(result, sys.stdout, sort_keys=True)
json.dump(result, sys.stdout, sort_keys=True, indent=indent)
print()

else:
out_path = str(path_out).format(number=i)
LOGGER.info("%sWriting batch #%d to <%s>", dry_run_prefix, i, out_path)
if not dry_run:
with open(out_path, "w") as out_file:
json.dump(result, out_file, sort_keys=True)
json.dump(result, out_file, sort_keys=True, indent=indent)

LOGGER.info("%sDone splitting.", dry_run_prefix)

Expand Down

0 comments on commit db8c5ff

Please sign in to comment.