Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import sys
- import os
- from analyzer import Analyzer
- from termcolor import colored
- def main():
- if len(sys.argv) != 2:
- sys.exit("Usage: ./tweets @screen_name")
- 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.checkTweet(sys.argv[1])
- for i in range (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 checkTweet(self, text):
- tweets = get_user_timeline(text, 50)
- if tweets == None:
- sys.exit("Error")
- final_score = []
- for tweet in tweets:
- score = 0
- tknzr = TweetTokenizer()
- tokens = tknzr.tokenize(tweet)
- for word in tokens:
- if word in self.positives:
- score += 1
- elif word in self.negatives:
- score -= 1
- else:
- score = 0
- scores = (score, tweet)
- final_score.append(scores)
- return final_score
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement