Merge pull request #863 from artoonie/master
This commit is contained in:
commit
e174443da3
|
@ -292,6 +292,9 @@ The following options are for the `archive` command specifically.
|
|||
- `--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
|
||||
- `--skip-comments`
|
||||
- Skip downloading all comments. This will result in a much shorter runtime.
|
||||
- Not compatible with --comment-context
|
||||
|
||||
### Cloner Options
|
||||
|
||||
|
|
|
@ -66,6 +66,7 @@ _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("--skip-comments", is_flag=True, default=None),
|
||||
]
|
||||
|
||||
|
||||
|
|
|
@ -10,11 +10,15 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
class SubmissionArchiveEntry(BaseArchiveEntry):
|
||||
def __init__(self, submission: praw.models.Submission) -> None:
|
||||
def __init__(self, submission: praw.models.Submission, include_comments: bool = True) -> None:
|
||||
super().__init__(submission)
|
||||
self._include_comments = include_comments
|
||||
|
||||
def compile(self) -> dict:
|
||||
comments = self._get_comments()
|
||||
if self._include_comments:
|
||||
comments = self._get_comments()
|
||||
else:
|
||||
comments = []
|
||||
self._get_post_details()
|
||||
out = self.post_details
|
||||
out["comments"] = comments
|
||||
|
|
|
@ -73,10 +73,12 @@ class Archiver(RedditConnector):
|
|||
results.append(sort(self.reddit_instance.redditor(user).comments, limit=self.args.limit))
|
||||
return results
|
||||
|
||||
@staticmethod
|
||||
def _pull_lever_entry_factory(praw_item: Union[praw.models.Submission, praw.models.Comment]) -> BaseArchiveEntry:
|
||||
def _pull_lever_entry_factory(
|
||||
self,
|
||||
praw_item: Union[praw.models.Submission, praw.models.Comment],
|
||||
) -> BaseArchiveEntry:
|
||||
if isinstance(praw_item, praw.models.Submission):
|
||||
return SubmissionArchiveEntry(praw_item)
|
||||
return SubmissionArchiveEntry(praw_item, not self.args.skip_comments)
|
||||
elif isinstance(praw_item, praw.models.Comment):
|
||||
return CommentArchiveEntry(praw_item)
|
||||
else:
|
||||
|
|
|
@ -58,6 +58,7 @@ class Configuration(Namespace):
|
|||
self.all_comments = False
|
||||
self.format = "json"
|
||||
self.comment_context: bool = False
|
||||
self.skip_comments = False
|
||||
|
||||
def process_click_arguments(self, context: click.Context) -> None:
|
||||
if context.params.get("opts") is not None:
|
||||
|
|
|
@ -16,6 +16,16 @@ def test_get_comments(test_submission_id: str, min_comments: int, reddit_instanc
|
|||
assert len(results) >= min_comments
|
||||
|
||||
|
||||
@pytest.mark.online
|
||||
@pytest.mark.reddit
|
||||
@pytest.mark.parametrize(("test_submission_id", "min_comments"), (("m3reby", 27),))
|
||||
def test_skip_comments(test_submission_id: str, min_comments: int, reddit_instance: praw.Reddit):
|
||||
test_submission = reddit_instance.submission(id=test_submission_id)
|
||||
test_archive_entry = SubmissionArchiveEntry(test_submission, False)
|
||||
results = test_archive_entry.compile()
|
||||
assert len(results["comments"]) == 0
|
||||
|
||||
|
||||
@pytest.mark.online
|
||||
@pytest.mark.reddit
|
||||
@pytest.mark.parametrize(
|
||||
|
|
|
@ -199,3 +199,16 @@ def test_user_serv_fail(test_args: list[str], response: int, tmp_path: Path):
|
|||
result = runner.invoke(cli, test_args)
|
||||
assert result.exit_code == 0
|
||||
assert f"received {response} HTTP response" in 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", (["--skip-comments", "--link", "gxqapql"],))
|
||||
def test_cli_archive_skip_comments(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 "Converting comment" not in result.output
|
||||
assert "Retrieving full comment tree for submission" not in result.output
|
||||
|
|
Loading…
Reference in a new issue