#!/usr/bin/env python3

import os
import sys
import helpers

from analyzer import Analyzer
from termcolor import colored


def main():

    # ensure proper usage
    if len(sys.argv) != 2:
        sys.exit("Usage: ./tweet @screen_name")

    # 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)

    # get the tweets of the user and analyze them
    tweets = helpers.get_user_timeline(sys.argv[1], 50)
    try:
        for tweet in tweets:
            score = analyzer.analyze(tweet)
            if score > 0.0:
                print (tweet),
                print(colored(":)", "green"))
            elif score < 0.0:
                print (tweet),
                print(colored(":(", "red"))
            else:
                print (tweet),
                print(colored(":|", "yellow"))

    except TypeError:
        sys.stderr.write("This user don't have any tweet\n")
    except Exception:
        sys.stderr.write("Some error occured")
        return 1


if __name__ == '__main__':
    main()


