1
0
Fork 0
mirror of synced 2024-06-02 18:34:37 +12:00

Merge pull request #863 from artoonie/master

This commit is contained in:
Serene 2023-06-18 13:22:43 +10:00 committed by GitHub
commit e174443da3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 5 deletions

View file

@ -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

View file

@ -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),
]

View file

@ -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

View file

@ -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:

View file

@ -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:

View file

@ -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(

View file

@ -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