base_archive_entry.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python3
  2. # coding=utf-8
  3. from abc import ABC, abstractmethod
  4. from praw.models import Comment, Submission
  5. class BaseArchiveEntry(ABC):
  6. def __init__(self, source: (Comment, Submission)):
  7. self.source = source
  8. self.post_details: dict = {}
  9. @abstractmethod
  10. def compile(self) -> dict:
  11. raise NotImplementedError
  12. @staticmethod
  13. def _convert_comment_to_dict(in_comment: Comment) -> dict:
  14. out_dict = {
  15. 'author': in_comment.author.name if in_comment.author else 'DELETED',
  16. 'id': in_comment.id,
  17. 'score': in_comment.score,
  18. 'subreddit': in_comment.subreddit.display_name,
  19. 'author_flair': in_comment.author_flair_text,
  20. 'submission': in_comment.submission.id,
  21. 'stickied': in_comment.stickied,
  22. 'body': in_comment.body,
  23. 'is_submitter': in_comment.is_submitter,
  24. 'distinguished': in_comment.distinguished,
  25. 'created_utc': in_comment.created_utc,
  26. 'parent_id': in_comment.parent_id,
  27. 'replies': [],
  28. }
  29. in_comment.replies.replace_more(0)
  30. for reply in in_comment.replies:
  31. out_dict['replies'].append(BaseArchiveEntry._convert_comment_to_dict(reply))
  32. return out_dict