-
Notifications
You must be signed in to change notification settings - Fork 95
/
tweet_sentiment.py
66 lines (47 loc) · 1.19 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import sys
import json
from pprint import pprint
def hw():
print 'Hello, world!'
def lines(fp):
print str(len(fp.readlines()))
def pri(y):
print y
def main():
sent_file = open(sys.argv[1])
tweet_file = open(sys.argv[2])
#hw()
#lines(sent_file)
#lines(tweet_file)
#data=[]
afinnfile = open(sys.argv[1])
scores = {} # initialize an empty dictionary
for line in afinnfile:
term, score = line.split("\t")
scores[term] = int(score)
#print scores.items()
new=open(sys.argv[2])
for line in new:
data=json.loads(line)
#pri(data)
sum=0
if "text" in data:
l=data["text"]
l2=l.encode('ascii','ignore')
#l3="hi i am ujjwal"
#pri(l2)
#for word in l3:
#print(word)
ter=l2.split(" ")
#print(ter)
for a in ter:
#print a
if a in scores:
sum=sum+scores.get(a)
print sum
#l3="hi i am ujjwal"
#print (l3)
#word=l3.split(" ")
#print word
if __name__ == '__main__':
main()