cathw commited on
Commit
cdbcdbd
·
verified ·
1 Parent(s): 01f62be

Upload reddit_climate_comment.py

Browse files
Files changed (1) hide show
  1. reddit_climate_comment.py +31 -29
reddit_climate_comment.py CHANGED
@@ -69,36 +69,37 @@ class NewDataset(GeneratorBasedBuilder):
69
  post_permalink = post['PostPermalink']
70
  comments = []
71
 
72
- for comment_id, comment_author in zip(post['comments']['CommentID'], post['comments']['CommentAuthor']):
73
- comment_body = post['comments'].get(comment_id, {}).get('CommentBody')
74
- comment_timestamp = post['comments'].get(comment_id, {}).get('CommentTimestamp')
75
- comment_upvotes = post['comments'].get(comment_id, {}).get('CommentUpvotes')
76
- comment_permalink = post['comments'].get(comment_id, {}).get('CommentPermalink')
77
- replies = []
78
- for reply_id, reply_author in zip(post['comments'].get(comment_id, {}).get('Replies', {}).get('ReplyID', []), post['comments'].get(comment_id, {}).get('Replies', {}).get('ReplyAuthor', [])):
79
- reply_body = post['comments'].get(comment_id, {}).get('Replies', {}).get(reply_id, {}).get('ReplyBody')
80
- reply_timestamp = post['comments'].get(comment_id, {}).get('Replies', {}).get(reply_id, {}).get('ReplyTimestamp')
81
- reply_upvotes = post['comments'].get(comment_id, {}).get('Replies', {}).get(reply_id, {}).get('ReplyUpvotes')
82
- reply_permalink = post['comments'].get(comment_id, {}).get('Replies', {}).get(reply_id, {}).get('ReplyPermalink')
83
- replies.append({
84
- "ReplyID": reply_id,
85
- "ReplyAuthor": reply_author,
86
- "ReplyBody": reply_body,
87
- "ReplyTimestamp": reply_timestamp,
88
- "ReplyUpvotes": reply_upvotes,
89
- "ReplyPermalink": reply_permalink
 
 
 
 
 
 
 
 
 
 
 
90
  })
91
-
92
- comments.append({
93
- "CommentID": comment_id,
94
- "CommentAuthor": comment_author,
95
- "CommentBody": comment_body,
96
- "CommentTimestamp": comment_timestamp,
97
- "CommentUpvotes": comment_upvotes,
98
- "CommentPermalink": comment_permalink,
99
- "Replies": replies
100
- })
101
-
102
  yield post_id, {
103
  "id": post_id,
104
  "post_title": post_title,
@@ -112,3 +113,4 @@ class NewDataset(GeneratorBasedBuilder):
112
  "post_permalink": post_permalink,
113
  "comments": comments
114
  }
 
 
69
  post_permalink = post['PostPermalink']
70
  comments = []
71
 
72
+ if 'comments' in post:
73
+ for comment_id, comment_author in zip(post['comments']['CommentID'], post['comments']['CommentAuthor']):
74
+ comment_body = post['comments'].get(comment_id, {}).get('CommentBody')
75
+ comment_timestamp = post['comments'].get(comment_id, {}).get('CommentTimestamp')
76
+ comment_upvotes = post['comments'].get(comment_id, {}).get('CommentUpvotes')
77
+ comment_permalink = post['comments'].get(comment_id, {}).get('CommentPermalink')
78
+ replies = []
79
+ for reply_id, reply_author in zip(post['comments'].get(comment_id, {}).get('Replies', {}).get('ReplyID', []), post['comments'].get(comment_id, {}).get('Replies', {}).get('ReplyAuthor', [])):
80
+ reply_body = post['comments'].get(comment_id, {}).get('Replies', {}).get(reply_id, {}).get('ReplyBody')
81
+ reply_timestamp = post['comments'].get(comment_id, {}).get('Replies', {}).get(reply_id, {}).get('ReplyTimestamp')
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": reply_id,
86
+ "ReplyAuthor": reply_author,
87
+ "ReplyBody": reply_body,
88
+ "ReplyTimestamp": reply_timestamp,
89
+ "ReplyUpvotes": reply_upvotes,
90
+ "ReplyPermalink": reply_permalink
91
+ })
92
+
93
+ comments.append({
94
+ "CommentID": comment_id,
95
+ "CommentAuthor": comment_author,
96
+ "CommentBody": comment_body,
97
+ "CommentTimestamp": comment_timestamp,
98
+ "CommentUpvotes": comment_upvotes,
99
+ "CommentPermalink": comment_permalink,
100
+ "Replies": replies
101
  })
102
+
 
 
 
 
 
 
 
 
 
 
103
  yield post_id, {
104
  "id": post_id,
105
  "post_title": post_title,
 
113
  "post_permalink": post_permalink,
114
  "comments": comments
115
  }
116
+