refactor(dataset creation): update API methods to return only posts
This commit is contained in:
25
dto/post.py
25
dto/post.py
@@ -1,3 +1,5 @@
|
||||
from dto.comment import Comment
|
||||
|
||||
class Post:
|
||||
def __init__(self,
|
||||
id: str,
|
||||
@@ -6,7 +8,8 @@ class Post:
|
||||
content: str,
|
||||
url: str,
|
||||
timestamp: float,
|
||||
source: str):
|
||||
source: str,
|
||||
comments: list[Comment]):
|
||||
self.id = id
|
||||
self.author = author
|
||||
self.title = title
|
||||
@@ -14,7 +17,25 @@ class Post:
|
||||
self.url = url
|
||||
self.timestamp = timestamp
|
||||
self.source = source
|
||||
self.comments = comments
|
||||
|
||||
# Optionals
|
||||
self.subreddit = None
|
||||
self.upvotes = None
|
||||
self.upvotes = None
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"id": self.id,
|
||||
"author": self.author,
|
||||
"title": self.title,
|
||||
"content": self.content,
|
||||
"url": self.url,
|
||||
"timestamp": self.timestamp,
|
||||
"source": self.source,
|
||||
"comments": [
|
||||
c.to_dict() if hasattr(c, "to_dict") else c
|
||||
for c in self.comments
|
||||
],
|
||||
"subreddit": self.subreddit,
|
||||
"upvotes": self.upvotes,
|
||||
}
|
||||
Reference in New Issue
Block a user