Refactor and update structure #20
@@ -1,6 +1,6 @@
|
||||
import os
|
||||
from praw import Reddit # type: ignore
|
||||
from praw.models import Submission, MoreComments # type: ignore
|
||||
from praw.models import Submission # type: ignore
|
||||
from app.base.social import SocialWrapper, SocialPost, SocialComment
|
||||
|
||||
|
||||
@@ -28,16 +28,14 @@ def extract_post(post: Submission) -> SocialPost:
|
||||
social.title = post.title
|
||||
social.description = post.selftext
|
||||
|
||||
for i, top_comment in enumerate(post.comments.list()):
|
||||
if i >= MAX_COMMENTS:
|
||||
break
|
||||
if isinstance(top_comment, MoreComments): #skip MoreComments objects
|
||||
continue
|
||||
|
||||
for top_comment in post.comments:
|
||||
comment = SocialComment()
|
||||
comment.time = str(top_comment.created)
|
||||
comment.description = top_comment.body
|
||||
social.comments.append(comment)
|
||||
|
||||
if len(social.comments) >= MAX_COMMENTS:
|
||||
break
|
||||
return social
|
||||
|
||||
class RedditWrapper(SocialWrapper):
|
||||
|
||||
@@ -51,7 +51,7 @@ class WrapperHandler(Generic[WrapperType]):
|
||||
log_info(f"{inspect.getsource(func).strip()} {inspect.getclosurevars(func).nonlocals}")
|
||||
|
|
||||
|
||||
iterations = 0
|
||||
error = ""
|
||||
error = "No error"
|
||||
while iterations < len(self.wrappers):
|
||||
wrapper = self.wrappers[self.index]
|
||||
wrapper_name = wrapper.__class__.__name__
|
||||
@@ -92,7 +92,7 @@ class WrapperHandler(Generic[WrapperType]):
|
||||
log_info(f"{inspect.getsource(func).strip()} {inspect.getclosurevars(func).nonlocals}")
|
||||
|
||||
results: dict[str, OutputType] = {}
|
||||
error = ""
|
||||
error = "No error"
|
||||
for wrapper in self.wrappers:
|
||||
wrapper_name = wrapper.__class__.__name__
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user
The variable 'error' is initialized but may be used uninitialized if no exception occurs in the while loop before the final raise statement.
[nitpick] The variable 'error' is initialized but may not be used if no exceptions occur in the loop. Consider initializing it only when needed or using a more descriptive default value.