cathw commited on
Commit
6bfb168
·
verified ·
1 Parent(s): cdbcdbd

Upload reddit_climate_comment.py

Browse files
Files changed (1) hide show
  1. 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
- 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({
@@ -95,7 +102,7 @@ class NewDataset(GeneratorBasedBuilder):
95
  "CommentAuthor": comment_author,
96
  "CommentBody": comment_body,
97
  "CommentTimestamp": comment_timestamp,
98
- "CommentUpvotes": comment_upvotes,
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
  }