Merge pull request #900 from Serene-Arc/feature_815
This commit is contained in:
commit
0635b16e74
|
@ -289,6 +289,7 @@ The following options are for the `archive` command specifically.
|
|||
- `json` (default)
|
||||
- `xml`
|
||||
- `yaml`
|
||||
- Can be specified multiple times
|
||||
- `--comment-context`
|
||||
- This option will, instead of downloading an individual comment, download the submission that comment is a part of
|
||||
- May result in a longer run time as it retrieves much more data
|
||||
|
|
|
@ -65,7 +65,7 @@ _downloader_options = [
|
|||
_archiver_options = [
|
||||
click.option("--all-comments", is_flag=True, default=None),
|
||||
click.option("--comment-context", is_flag=True, default=None),
|
||||
click.option("-f", "--format", type=click.Choice(("xml", "json", "yaml")), default=None),
|
||||
click.option("-f", "--format", type=click.Choice(("xml", "json", "yaml")), default=None, multiple=True),
|
||||
click.option("--skip-comments", is_flag=True, default=None),
|
||||
]
|
||||
|
||||
|
|
|
@ -89,14 +89,15 @@ class Archiver(RedditConnector):
|
|||
logger.debug(f"Converting comment {praw_item.id} to submission {praw_item.submission.id}")
|
||||
praw_item = praw_item.submission
|
||||
archive_entry = self._pull_lever_entry_factory(praw_item)
|
||||
if self.args.format == "json":
|
||||
self._write_entry_json(archive_entry)
|
||||
elif self.args.format == "xml":
|
||||
self._write_entry_xml(archive_entry)
|
||||
elif self.args.format == "yaml":
|
||||
self._write_entry_yaml(archive_entry)
|
||||
else:
|
||||
raise ArchiverError(f"Unknown format {self.args.format!r} given")
|
||||
for format_specification in self.args.format:
|
||||
if format_specification == "json":
|
||||
self._write_entry_json(archive_entry)
|
||||
elif format_specification == "xml":
|
||||
self._write_entry_xml(archive_entry)
|
||||
elif format_specification == "yaml":
|
||||
self._write_entry_yaml(archive_entry)
|
||||
else:
|
||||
raise ArchiverError(f"Unknown format {self.args.format!r} given")
|
||||
logger.info(f"Record for entry item {praw_item.id} written to disk")
|
||||
|
||||
def _write_entry_json(self, entry: BaseArchiveEntry) -> None:
|
||||
|
|
|
@ -56,7 +56,9 @@ class Configuration(Namespace):
|
|||
|
||||
# Archiver-specific options
|
||||
self.all_comments = False
|
||||
self.format = "json"
|
||||
self.format = [
|
||||
"json",
|
||||
]
|
||||
self.comment_context: bool = False
|
||||
self.skip_comments = False
|
||||
|
||||
|
|
|
@ -52,6 +52,22 @@ def test_cli_archive_single(test_args: list[str], tmp_path: Path):
|
|||
assert re.search(r"Writing entry .*? to file in .*? format", result.output)
|
||||
|
||||
|
||||
@pytest.mark.online
|
||||
@pytest.mark.reddit
|
||||
@pytest.mark.skipif(not does_test_config_exist, reason="A test config file is required for integration tests")
|
||||
@pytest.mark.parametrize(
|
||||
"test_args",
|
||||
(["-l", "m2601g", "-f", "yaml", "-f", "json"],),
|
||||
)
|
||||
def test_cli_archive_single_multi_format(test_args: list[str], tmp_path: Path):
|
||||
runner = CliRunner()
|
||||
test_args = create_basic_args_for_archive_runner(test_args, tmp_path)
|
||||
result = runner.invoke(cli, test_args)
|
||||
assert result.exit_code == 0
|
||||
assert re.search(r"Writing entry .*? to file in YAML format", result.output)
|
||||
assert re.search(r"Writing entry .*? to file in JSON format", result.output)
|
||||
|
||||
|
||||
@pytest.mark.online
|
||||
@pytest.mark.reddit
|
||||
@pytest.mark.skipif(not does_test_config_exist, reason="A test config file is required for integration tests")
|
||||
|
|
Loading…
Reference in a new issue