ahmedraza

tweets

Jan 22nd, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. import sys
  3. import os
  4. import helpers
  5. from analyzer import Analyzer
  6. from termcolor import colored
  7.  
  8. def main():
  9.     if len(sys.argv) != 2:
  10.         sys.exit("Usage: ./tweets @screen_name")
  11.        
  12.     screen_name = sys.argv[1]
  13.     tweets = helpers.get_user_timeline(screen_name)
  14.     # absolute paths to lists
  15.     positives = os.path.join(sys.path[0], "positive-words.txt")
  16.     negatives = os.path.join(sys.path[0], "negative-words.txt")
  17.  
  18.     # instantiate analyzer
  19.     analyzer = Analyzer(positives, negatives)
  20.     positive,negative,neutral = 0.0,0.0,0.0
  21.     # analyze tweet
  22.     for tweet in tweets:
  23.         score = analyzer.analyze(tweet)
  24.        
  25.         if score > 0.0:
  26.             print(colored(":)", "green"))
  27.         elif score < 0.0:
  28.             print(colored(":(", "red"))
  29.         else:
  30.             print(colored(":|", "yellow"))
  31.        
  32.    
  33. if __name__ == "__main__":
  34.     main()
Add Comment
Please, Sign In to add comment