-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtweets
More file actions
executable file
·49 lines (36 loc) · 1.15 KB
/
tweets
File metadata and controls
executable file
·49 lines (36 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/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()