-
Notifications
You must be signed in to change notification settings - Fork 0
/
top_ten.py
37 lines (30 loc) · 876 Bytes
/
top_ten.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
import sys
import json
import os
def main():
tweet_file = open(sys.argv[1])
import json
tweets = []
for line in tweet_file:
try:
tweets.append(json.loads(line))
except:
pass
tagscore={}
for tweet in tweets:
#print tweet
if 'entities' and 'text' in tweet.keys():
for ht in tweet["entities"]['hashtags']:
#print ht
tag=ht['text']
if tag in tagscore.keys():
tagscore[tag]=tagscore[tag]+1
else:
tagscore[tag]=1
tagscore2=sorted(tagscore.items(),key=lambda x:x[1],reverse=True)
for score in tagscore2[:10]:
print score[0], score[1]
#for key, value in tagscore2.items():
# print key,value
if __name__ == '__main__':
main()