0

Trying to run this, but getting an error at the very bottom "elif" statement while trying to set the colour saying it is invalid syntax. I don't know why. Also, am I doing this problem correctly? I think I have done everything for tweets but I am not sure

#!/usr/bin/env python3
import sys
from helpers import get_user_timeline
from anaylzer import analyze
from termcolor import colored
import nltk
import os

def main():
    #set screen name to argv1
    screen_name = sys.argv[1].strip("@")

    #set absolute paths to the words lists
    positivestxt = os.path.join(sys.path[0], "positive-words.txt")
    negativestxt = os.path.join(sys.path[0], "negative-words.txt")

    #ensure proper usage
    if len(sys.argv) != 2:
        print("Usage: ./tweets @screen_name")
        return 1

    #ensure screen name is valid
    elif get_user_timeline(screen_name) == None:
        print("screen name not valid (does not exist or may be a private account)")
        sys.exit


    else:
        #get user timeline tweets, 50 of them from the inputed screen name
        tweets = get_user_timeline(screen_name, 50)

        #instantiate analyzer with inputs positivestxt and negativestxt
        analyzer = Analyzer(positivestxt, negativestxt)

        #for each word in tokenslist analze the score and print appropriate colour
        tokenslist = nltk.tokenize.TweetTokenizer(tweets)
        for word in tokenslist:
            wordscore = analyzer.analyze(word)

            if wordscore > 0.0:
                print(colored(wordscore + word, "green")

            elif wordscore < 0.0:
                print(colored(wordscore + word), "red")

            else:
                print(colored(wordscore + word, "yellow")


if __name__ == "main":
    main()
1

Looks like unbalanced parentheses in the line above the elif.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .