-
Notifications
You must be signed in to change notification settings - Fork 0
/
notes
51 lines (41 loc) · 2.01 KB
/
notes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{1}:
for comment, replies in all_comments:
if len(comment) >= 3:
print(remove_emojis(comment))
if len(replies) > 0:
print("There are", len(replies), "replies")
print("\tReplies:")
for reply in replies:
print("\t" + remove_emojis(reply))
print()
{2}:
# get number of replies
reply_count = comment['snippet']['totalReplyCount']
all_replies = []
# if replies greater than 0
if reply_count > 0:
# get first 100 replies
replies_list = youtube.comments().list(part='snippet', maxResults=100, parentId=comment['id']).execute()
for reply in replies_list['items']:
# add reply to list
all_replies.append(reply['snippet']['textDisplay'])
# check for more replies
while "nextPageToken" in replies_list:
token_reply = replies_list['nextPageToken']
# get next set of 100 replies
replies_list = youtube.comments().list(part = 'snippet', maxResults = 100, parentId = comment['id'], pageToken = token_reply).execute()
for reply in replies_list['items']:
# add reply to list
all_replies.append(reply['snippet']['textDisplay'])
# add all replies to the comment
all_comments[-1].append(all_replies)
{3}:
# recursive function to get all replies in a comment thread
def get_replies(comment_id, token):
replies_response = yt_object.comments().list(part = 'snippet', maxResults = 100, parentId = comment_id, pageToken = token).execute()
for reply in replies_response['items']:
all_comments.append(reply['snippet']['textDisplay'])
if replies_response.get("nextPageToken"):
return get_replies(comment_id, replies_response['nextPageToken'])
else:
return []