-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtweet_sentiment.py
46 lines (39 loc) · 1.04 KB
/
tweet_sentiment.py
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
import sys
import json
def hw():
print 'Hello, world!'
def lines(fp):
print str(len(fp.readlines()))
def main():
sent_file = open(sys.argv[1])
tweet_file = open(sys.argv[2])
#hw()
#lines(sent_file)
#lines(tweet_file)
tweets = []
for line in tweet_file:
#print line
tweet_line = json.loads(line)
#print tweet_line
if "text" in tweet_line:
tweets.append(tweet_line["text"].encode('utf-8'))
#print tweets
#print len(tweets)
#print "aha"
scores = {}
for line in sent_file:
term, score = line.split("\t")
scores[term] = float(score)
#print "oho"
for item in tweets:
total = 0.0
words = []
words = item.split(" ")
for everyword in words:
if everyword in scores:
total += scores[term]
#print total
sys.stdout.write(str(total))
sys.stdout.write("\n")
if __name__ == '__main__':
main()