I need some help with tweets. Or just help me get what inspiration to get from smile for it, as per the specs.
Here's my code:
#!/usr/bin/env python3
import os
import sys
import nltk
from analyzer import Analyzer
from termcolor import colored
from helpers import get_user_timeline
def main():
if len(sys.argv) != 2:
sys.exit("Usage: ./tweets twitterhandle")
positives = os.path.join(sys.path[0], "positive-words.txt")
negatives = os.path.join(sys.path[0], "negative-words.txt")
analyzer = Analyzer(positives, negatives)
final_score = analyzer.analyze(sys.argv[1])
for i in range(0, final_score):
score = final_score[i]
print(score[0], end="")
if score[i] > 0.0:
print(colored(score, "green"))
elif score[i] < 0.0:
print(colored(score, "red"))
else:
print(colored(score, "yellow"))
if __name__ == "__main__":
main()
def tweet_analyze(self, text):
tweets = get_user_timeline(text, 50)
if tweets == None:
sys.exit("Error: problem getting tweets")
print(tweets)
final_score = []
for tweet in tweets:
score = 0
tokenizer = nltk.tokenize.TweetTokenizer()
tokens = tokenizer.tokenize(tweet)
if tweet in self.positives:
score += 1
elif tweet in self.negatives:
score -= 1
final_score[tweet] = score
return final_score
And since I'm not calling tweet_analyze anywhere, is it better to delete that and call get_user_timeline() in main()? What do I pass in to get_user_timeline(), though? And if I have to call it somewhere, then where?