Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import os
- import sys
- import nltk
- from analyzer import Analyzer
- from termcolor import colored
- from helpers import get_user_timeline
- def main():
- if len(sys.argv[1]) != 2:
- sys.exit("Usage: ./tweets twitterhandle")
- positives = os.path.join(sys.path[0], "positive-words.txt")
- negatives = os.path.join(sys.path[0], "negative-words.txt")
- analyzer = Analyzer(positives, negatives)
- final_score = analyzer.analyze(sys.argv[1])
- for i in range(0, len(final_score)):
- score = final_score[i]
- print(score[0], end="")
- if score[0] > 0.0:
- print(colored(score, "green"))
- elif score[0] < 0.0:
- print(colored(score, "red"))
- else:
- print(colored(score, "yellow"))
- if __name__ == "__main__":
- main()
- def tweet_analyze(self, text):
- tweets = get_user_timeline(text, 50)
- if tweets == None:
- sys.exit("Error: problem getting tweets")
- print(tweets)
- final_score = []
- for tweet in tweets:
- score = 0
- tokenizer = nltk.tokenize.TweetTokenizer()
- tokens = tokenizer.tokenize(tweet)
- if tweet in self.positives:
- score += 1
- elif tweet in self.negatives:
- score -= 1
- final_score[tweet] = score
- return final_score
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement