def _pull_lever_entry_factory(praw_item: (praw.models.Submission, praw.models.Comment)) -> BaseArchiveEntry: if isinstance(praw_item, praw.models.Submission): return SubmissionArchiveEntry(praw_item) elif isinstance(praw_item, praw.models.Comment): return CommentArchiveEntry(praw_item) else: 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)): 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} given') logger.info(f'Record for entry item {praw_item.id} written to disk')
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) 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} given') logger.info(f'Record for entry item {praw_item.id} written to disk')