#!/usr/bin/env python3

# TODO
import os
import sys

from analyzer import Analyzer
from termcolor import colored
from helpers import get_user_timeline

def main():
    # ensure proper usage
    if len(sys.argv) != 2:
        sys.exit("Usage: ./tweets @screen_name")
        
    # check if the user is valid
    tweets_100 = get_user_timeline(sys.argv[1])  #should return a list of string, each string is a tweet
    if tweets_100 == None:
        sys.exit("Invalid user provided")
        
        # absolute paths to lists
    positives = os.path.join(sys.path[0], "positive-words.txt")
    negatives = os.path.join(sys.path[0], "negative-words.txt")
    
    #instantiate analyzer
    analyzer = Analyzer(positives, negatives)
    for every_tweet in tweets_100:
        each_score = analyzer.analyze(every_tweet)
        if each_score > 0.0:
            print(colored("1 {}".format(every_tweet), "green"))
        elif each_score < 0.0:
            print(colored("-1 {}".format(every_tweet), "red"))
        else:
            print(colored("0 {}".format(every_tweet), "yellow"))

if __name__ == "__main__":
    main()
    