Datasets:
Upload reddit_climate_comment.py
Browse files- reddit_climate_comment.py +24 -18
reddit_climate_comment.py
CHANGED
|
@@ -70,24 +70,31 @@ class NewDataset(GeneratorBasedBuilder):
|
|
| 70 |
comments = []
|
| 71 |
|
| 72 |
if 'comments' in post:
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
replies = []
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
reply_upvotes = post['comments'].get(comment_id, {}).get('Replies', {}).get(reply_id, {}).get('ReplyUpvotes')
|
| 83 |
-
reply_permalink = post['comments'].get(comment_id, {}).get('Replies', {}).get(reply_id, {}).get('ReplyPermalink')
|
| 84 |
replies.append({
|
| 85 |
-
"ReplyID":
|
| 86 |
-
"ReplyAuthor":
|
| 87 |
-
"ReplyBody":
|
| 88 |
-
"ReplyTimestamp":
|
| 89 |
-
"ReplyUpvotes":
|
| 90 |
-
"ReplyPermalink":
|
| 91 |
})
|
| 92 |
|
| 93 |
comments.append({
|
|
@@ -95,7 +102,7 @@ class NewDataset(GeneratorBasedBuilder):
|
|
| 95 |
"CommentAuthor": comment_author,
|
| 96 |
"CommentBody": comment_body,
|
| 97 |
"CommentTimestamp": comment_timestamp,
|
| 98 |
-
"CommentUpvotes":
|
| 99 |
"CommentPermalink": comment_permalink,
|
| 100 |
"Replies": replies
|
| 101 |
})
|
|
@@ -113,4 +120,3 @@ class NewDataset(GeneratorBasedBuilder):
|
|
| 113 |
"post_permalink": post_permalink,
|
| 114 |
"comments": comments
|
| 115 |
}
|
| 116 |
-
|
|
|
|
| 70 |
comments = []
|
| 71 |
|
| 72 |
if 'comments' in post:
|
| 73 |
+
comment_ids = post['comments'].get('CommentID', [])
|
| 74 |
+
comment_authors = post['comments'].get('CommentAuthor', [])
|
| 75 |
+
comment_bodies = post['comments'].get('CommentBody', [])
|
| 76 |
+
comment_timestamps = post['comments'].get('CommentTimestamp', [])
|
| 77 |
+
comment_upvotes = post['comments'].get('CommentUpvotes', [])
|
| 78 |
+
comment_permalinks = post['comments'].get('CommentPermalink', [])
|
| 79 |
+
reply_lists = post['comments'].get('Replies', [])
|
| 80 |
+
|
| 81 |
+
for i, comment_id in enumerate(comment_ids):
|
| 82 |
+
comment_author = comment_authors[i]
|
| 83 |
+
comment_body = comment_bodies[i] if i < len(comment_bodies) else None
|
| 84 |
+
comment_timestamp = comment_timestamps[i] if i < len(comment_timestamps) else None
|
| 85 |
+
comment_upvote = comment_upvotes[i] if i < len(comment_upvotes) else None
|
| 86 |
+
comment_permalink = comment_permalinks[i] if i < len(comment_permalinks) else None
|
| 87 |
replies = []
|
| 88 |
+
|
| 89 |
+
reply_list = reply_lists[i] if i < len(reply_lists) else []
|
| 90 |
+
for reply in reply_list:
|
|
|
|
|
|
|
| 91 |
replies.append({
|
| 92 |
+
"ReplyID": reply.get("ReplyID", ""),
|
| 93 |
+
"ReplyAuthor": reply.get("ReplyAuthor", ""),
|
| 94 |
+
"ReplyBody": reply.get("ReplyBody", ""),
|
| 95 |
+
"ReplyTimestamp": reply.get("ReplyTimestamp", ""),
|
| 96 |
+
"ReplyUpvotes": reply.get("ReplyUpvotes", ""),
|
| 97 |
+
"ReplyPermalink": reply.get("ReplyPermalink", "")
|
| 98 |
})
|
| 99 |
|
| 100 |
comments.append({
|
|
|
|
| 102 |
"CommentAuthor": comment_author,
|
| 103 |
"CommentBody": comment_body,
|
| 104 |
"CommentTimestamp": comment_timestamp,
|
| 105 |
+
"CommentUpvotes": comment_upvote,
|
| 106 |
"CommentPermalink": comment_permalink,
|
| 107 |
"Replies": replies
|
| 108 |
})
|
|
|
|
| 120 |
"post_permalink": post_permalink,
|
| 121 |
"comments": comments
|
| 122 |
}
|
|
|