I am using the following code to identify how toxic comments in a data frame are. But I keep getting the 'HTTPError: HTTP Error 429: Too Many Requests'. What should I do?
def aggressiveLanguage_mapper(input_data):
key = "my_key"
p = PerspectiveAPI(key)
input_data['insult_prob'] = np.nan
input_data['toxicity_prob'] = np.nan
input_data['threat_prob'] = np.nan
ignore_comments_counter = 0
j = 0
#additional code to resolve an error
type_base = type(input_data['parent_id'].iloc[0])
for ind, row in input_data.iterrows():
j += 1
if j % 60 == 0:
time.sleep(15)
print('finished comment '+str(j)+'/'+str(len(input_data)))
curr_author = row['author']
curr_subreddit_id = row['subreddit_id']
curr_id = row['id']
curr_comment_body = row['body']
#check the aggressive language probability in the comment body
result = p.score(curr_comment_body, ["INSULT","TOXICITY","THREAT"])
input_data.at[ind,'insult_prob'] = result["INSULT"]
input_data.at[ind,'toxicity_prob'] = result["TOXICITY"]
input_data.at[ind,'threat_prob'] = result["THREAT"]
#time.sleep(5)
print('total number of comments ignored: ' +str(ignore_comments_counter))
return input_data