refactor(dataset creation): update API methods to return only posts

This commit is contained in:
2026-02-09 21:20:08 +00:00
parent 645d2fdfdb
commit ec91904481
6 changed files with 87 additions and 65 deletions

View File

@@ -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,
}