-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtop_ten.py
More file actions
47 lines (38 loc) · 1.03 KB
/
top_ten.py
File metadata and controls
47 lines (38 loc) · 1.03 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
import sys
import json
import collections
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[1])
#hw()
#lines(sent_file)
#lines(tweet_file)
tags=[]
json_dict={}
frequency={}
tweet_file=open(sys.argv[1])
for line in tweet_file:
json_dict=json.loads(line)
if 'entities' in json_dict.keys():
#print json_dict["text"]
tags=json_dict['entities']['hashtags']
for tag in tags:
if 'text' in tag:
hashtag=tag['text']
if hashtag not in frequency:
frequency[hashtag]=1
elif hashtag in frequency:
frequency[hashtag]+=1
print frequency.items()
sort_tags=sorted(frequency, key=frequency.get, reverse=True)
#print sort_tags
for k in sort_tags[:10]:
print k, frequency[k]
#topten=Counter(frequency).most_common()[:10]
#print content[2]
if __name__ == '__main__':
main()