forked from sd17spring/TextMining
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataAnalysis.py
More file actions
28 lines (23 loc) · 827 Bytes
/
dataAnalysis.py
File metadata and controls
28 lines (23 loc) · 827 Bytes
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
import pickle
from bs4 import BeautifulSoup
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
def analyzer(filename):
input_file = open(filename, 'rb')
websitee = pickle.load(input_file)
soup = BeautifulSoup(websitee, "html.parser")
text = soup.get_text()
count = 0
newtext = text.split()
for i in newtext:
if(i == "trump" or i == "Trump"):
count += 1
analyze = SentimentIntensityAnalyzer()
scores = analyze.polarity_scores(text)
return count, scores
if __name__ == "__main__":
websites = ['bbc.pickle', 'cnn.pickle', 'foxnews.pickle']
for i in websites:
count = analyzer(i)[0]
scores = analyzer(i)[1]
print("Number of times Trump is mentioned: " , count)
print("Positivity/Negativity score: ", scores)