Advertisement
Guest User

Untitled

a guest
Jan 11th, 2017
697
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import sys
  4. import os
  5.  
  6. from analyzer import Analyzer
  7. from termcolor import colored
  8.  
  9. def main():
  10. if len(sys.argv) != 2:
  11. sys.exit("Usage: ./tweets @screen_name")
  12.  
  13. positives = os.path.join(sys.path[0], "positive-words.txt")
  14. negatives = os.path.join(sys.path[0], "negative-words.txt")
  15.  
  16. analyzer = Analyzer(positives, negatives)
  17.  
  18. final_score = analyzer.checkTweet(sys.argv[1])
  19.  
  20. for i in range (len(final_score)):
  21. score = final_score[i]
  22. print(score[0], end="")
  23. if score[0] > 0.0:
  24. print(colored(score, "green"))
  25. elif score[0] < 0.0:
  26. print(colored(score, "red"))
  27. else:
  28. print(colored(score, "yellow"))
  29.  
  30.  
  31. if __name__ == "__main__":
  32. main()
  33.  
  34.  
  35.  
  36. def checkTweet(self, text):
  37. tweets = get_user_timeline(text, 50)
  38. if tweets == None:
  39. sys.exit("Error")
  40.  
  41. final_score = []
  42. for tweet in tweets:
  43. score = 0
  44. tknzr = TweetTokenizer()
  45. tokens = tknzr.tokenize(tweet)
  46. for word in tokens:
  47. if word in self.positives:
  48. score += 1
  49. elif word in self.negatives:
  50. score -= 1
  51. else:
  52. score = 0
  53. scores = (score, tweet)
  54. final_score.append(scores)
  55.  
  56. return final_score
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement