1
0
Fork 0
mirror of synced 2024-06-22 16:10:36 +12:00

Merge pull request #457 from Serene-Arc/enhancement_322

Add option for archiver full context
This commit is contained in:
Ali Parlakçı 2021-06-19 13:56:04 +03:00 committed by GitHub
commit 71930e06a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 1 deletions

View file

@ -196,6 +196,9 @@ The following options are for the `archive` command specifically.
- `json` (default)
- `xml`
- `yaml`
- `--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
### Cloner Options

View file

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

View file

@ -61,6 +61,9 @@ class Archiver(RedditConnector):
raise ArchiverError(f'Factory failed to classify item of type {type(praw_item).__name__}')
def write_entry(self, praw_item: (praw.models.Submission, praw.models.Comment)):
if self.args.comment_context and isinstance(praw_item, praw.models.Comment):
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)

View file

@ -41,8 +41,9 @@ class Configuration(Namespace):
self.verbose: int = 0
# Archiver-specific options
self.format = 'json'
self.all_comments = False
self.format = 'json'
self.comment_context: bool = False
def process_click_arguments(self, context: click.Context):
for arg_key in context.params.keys():

View file

@ -252,6 +252,20 @@ def test_cli_archive_all_user_comments(test_args: list[str], tmp_path: Path):
assert result.exit_code == 0
@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', (
['--full-context', '--link', 'gxqapql'],
))
def test_cli_archive_full_context(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' in result.output
@pytest.mark.online
@pytest.mark.reddit
@pytest.mark.slow