Skip to content

Instantly share code, notes, and snippets.

@micseydel
Created December 9, 2019 16:10
Show Gist options
  • Save micseydel/aa4b79ba5a8814bdcc54d713e1853ef1 to your computer and use it in GitHub Desktop.
Save micseydel/aa4b79ba5a8814bdcc54d713e1853ef1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import sys
from urllib.request import urlopen
# python3 -m pip install --user textblob
# python3 -m textblob.download_corpora
from textblob import TextBlob
def relevant_words():
# https://github.com/dwyl/english-words/blob/master/words.txt
resp = urlopen("https://raw.githubusercontent.com/dwyl/english-words/master/words.txt")
for word in resp:
if word.startswith((b'dis', b'de')):
yield word.decode()
positive = 0
negative = 0
neutral = 0
for word in relevant_words():
analysis = TextBlob(word)
if analysis.sentiment.polarity > 0:
positive += 1
elif analysis.sentiment.polarity == 0:
neutral += 1
else:
negative += 1
total = positive + neutral + negative
print("Positive: {:.1f}%".format(positive / total * 100))
print("Negative: {:.1f}%".format(negative / total * 100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment