-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetEmails.py
41 lines (30 loc) · 1.29 KB
/
getEmails.py
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
import json
from bs4 import BeautifulSoup
from promptflow import tool
from nltk.sentiment.vader import SentimentIntensityAnalyzer
from textblob import TextBlob
@tool
def process_json_with_sentiment_analysis():
with open('data.json', 'r') as file:
json_data = json.load(file)
contents = [item['body']['content'] for item in json_data['value']]
def convert_html_to_text(html):
soup = BeautifulSoup(html, 'html.parser')
return soup.get_text()
plain_texts = [convert_html_to_text(content) if any(tag for tag in BeautifulSoup(content, 'html.parser').find_all()) else content for content in contents]
sid = SentimentIntensityAnalyzer()
analyses = []
for text in plain_texts:
sentiment_scores = sid.polarity_scores(text)
sentiment = "Positive" if sentiment_scores['compound'] > 0 else "Negative" if sentiment_scores['compound'] < 0 else "Neutral"
text_blob = TextBlob(text)
subjectivity = text_blob.sentiment.subjectivity
analysis = {
"content": text,
"Sentiment": sentiment,
"Subjectivity": subjectivity
}
analyses.append(analysis)
return analyses
result = process_json_with_sentiment_analysis()
print(json.dumps(result, indent=2))