-
Notifications
You must be signed in to change notification settings - Fork 95
/
happiest_state.py
101 lines (70 loc) · 2.17 KB
/
happiest_state.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import sys
import json
from pprint import pprint
import operator
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()
d={}
new = open(sys.argv[2])
for line in new:
data=json.loads(line)
#pri(data)
sum=0
#print sum
if "place" in data:
if (sum==0):
#l=data["place"]
#print 5
if (sum==0):
fn=data["place"]
#print fn
if (fn!=None):
#print fn
cc=fn["country_code"]
if (cc=="US"):
funa=fn["full_name"]
#print funa
ters=funa.split(", ")
#print ters[1]
t=ters[1]
sum=0
if "text" in data:
l5=data["text"]
l2=l5.encode('ascii','ignore')
ter=l2.split(" ")
for a in ter:
if a in scores:
sum=sum+scores.get(a)
#print sum, t
if t in d:
#print "yuyiu"
#print t
d[t]=(float(d[t])+sum)/2
else:
d.update({t:sum})
#print t
#print d
#print "f"
#for t in d.items():
#print t, sum
#print "foo"
print max(d.iteritems(), key=operator.itemgetter(1))[0]
if __name__ == '__main__':
main()