Datasets:
Upload reddit_climate_comment.py
Browse files- reddit_climate_comment.py +34 -1
reddit_climate_comment.py
CHANGED
|
@@ -67,7 +67,40 @@ class NewDataset(GeneratorBasedBuilder):
|
|
| 67 |
post_timestamp = post['PostTimestamp']
|
| 68 |
post_upvotes = int(post['PostUpvotes']) if post['PostUpvotes'] else None
|
| 69 |
post_permalink = post['PostPermalink']
|
| 70 |
-
comments =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
yield post_id, {
|
| 73 |
"id": post_id,
|
|
|
|
| 67 |
post_timestamp = post['PostTimestamp']
|
| 68 |
post_upvotes = int(post['PostUpvotes']) if post['PostUpvotes'] else None
|
| 69 |
post_permalink = post['PostPermalink']
|
| 70 |
+
comments = []
|
| 71 |
+
|
| 72 |
+
for i in range(0,len(post['Comments'])):
|
| 73 |
+
comment_id = post['Comments']['CommentID'][i]
|
| 74 |
+
comment_author = post['Comments']['CommentAuthor'][i]
|
| 75 |
+
comment_body = post['Comments']['CommentBody'][i] if post['Comments']['CommentBody'][i] != "" else None
|
| 76 |
+
comment_timestamp = post['Comments']['CommentTimestamp'][i]
|
| 77 |
+
comment_upvotes = int(post['Comments']['CommentUpvotes'][i]) if post['Comments']['CommentUpvotes'][i] else None
|
| 78 |
+
comment_permalink = post['Comments']['CommentPermalink'][i]
|
| 79 |
+
replies = []
|
| 80 |
+
comments.append({
|
| 81 |
+
"CommentID": comment_id,
|
| 82 |
+
"CommentAuthor": comment_author,
|
| 83 |
+
"CommentBody": comment_body,
|
| 84 |
+
"CommentTimestamp": comment_timestamp,
|
| 85 |
+
"CommentUpvotes": comment_upvotes,
|
| 86 |
+
"CommentPermalink": comment_permalink,
|
| 87 |
+
"Replies": replies
|
| 88 |
+
})
|
| 89 |
+
for reply in post['Comments'][i].get('Replies', []):
|
| 90 |
+
reply_id = reply['ReplyID']
|
| 91 |
+
reply_author = reply['ReplyAuthor']
|
| 92 |
+
reply_body = reply['ReplyBody'] if reply['ReplyBody'] != "" else None
|
| 93 |
+
reply_timestamp = reply['ReplyTimestamp']
|
| 94 |
+
reply_upvotes = int(reply['ReplyUpvotes']) if reply['ReplyUpvotes'] else None
|
| 95 |
+
reply_permalink = reply['ReplyPermalink']
|
| 96 |
+
replies.append({
|
| 97 |
+
"ReplyID": reply_id,
|
| 98 |
+
"ReplyAuthor": reply_author,
|
| 99 |
+
"ReplyBody": reply_body,
|
| 100 |
+
"ReplyTimestamp": reply_timestamp,
|
| 101 |
+
"ReplyUpvotes": reply_upvotes,
|
| 102 |
+
"ReplyPermalink": reply_permalink
|
| 103 |
+
})
|
| 104 |
|
| 105 |
yield post_id, {
|
| 106 |
"id": post_id,
|