#!/usr/bin/env python3

import sys
import os
from analyzer import Analyzer
import helpers
from termcolor import colored
from flask import Flask, request


def main():
    
    
    
    if len(sys.argv) != 2:
        sys.exit("Usage: ./tweets @twitter_user")
        
   
    positives = os.path.join(sys.path[0], "positive-words.txt")
    negatives = os.path.join(sys.path[0], "negative-words.txt")

    
    analyzer = Analyzer(positives, negatives)
    
    
    tweets = helpers.get_user_timeline(sys.argv[1].lstrip('@'))
    
    
    score = 0
    
    
    if tweets == None:
        print("No tweets for", sys.argv[1])
        sys.exit(1)
        
    
    for i in range(50):
        if i >= len(tweets):
            break
        score = analyzer.analyze(tweets[i])
        if score > 0.0:
            print("",score,colored(tweets[i], "green"))
        elif score < 0.0:
            print(score,colored(tweets[i], "red"))
        else:
            print("",score,colored(tweets[i], "yellow"))
    
    
    
if __name__ == '__main__':
    main()