forked from adi0509/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharticle_sentiment.py
More file actions
37 lines (28 loc) · 820 Bytes
/
article_sentiment.py
File metadata and controls
37 lines (28 loc) · 820 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
29
30
31
32
33
34
35
36
37
#Get the sentiment of articles from the internet
#pip install newspaper3k
#Import the libraries
from textblob import TextBlob
import nltk
from newspaper import Article
#Get the article
url = 'https://everythingcomputerscience.com/'
article = Article(url)
# Do some NLP
article.download() #Downloads the link’s HTML content
article.parse() #Parse the article
nltk.download('punkt')#1 time download of the sentence tokenizer
article.nlp()# Keyword extraction wrapper
text = article.summary
#print text
print(text)
obj = TextBlob(text)
#returns the sentiment of text
#by returning a value between -1.0 and 1.0
sentiment = obj.sentiment.polarity
print(sentiment)
if sentiment == 0:
print('The article is neutral')
elif sentiment > 0:
print('The article is positive')
else:
print('The article is negative')