-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathreadJson.py
67 lines (52 loc) · 1.68 KB
/
readJson.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 json,ast
tweets=[]
with open('twts4.txt','r') as f:
while True:
t=f.readline()
if (not t):
break
tweets.append(ast.literal_eval(t))
print(len(tweets))
ids=[]
#print(len(tweets))
class User:
def __init__(self,id,name,fllwr):
self.id=id
self.name=name
self.fllwr=fllwr
users=[]
for tweet in tweets:
u=User(tweet['user']['id'],tweet['user']['screen_name'],tweet['user']['followers_count'])
if (u.id not in ids and tweet['user']['verified']==1):
users.append(u)
ids.append(tweet['user']['id'])
if ('retweeted_status' in tweet.keys()):
u=User(tweet['retweeted_status']['user']['id'],tweet['retweeted_status']['user']['screen_name'],tweet['retweeted_status']['user']['followers_count'])
if (u.id not in ids and tweet['retweeted_status']['user']['verified']==1) :
users.append(u)
ids.append(tweet['retweeted_status']['user']['id'])
#users=list(set(users))
print(len(users))
import operator
users.sort(key=operator.attrgetter('fllwr'),reverse=1)
import csv
with open('users1.csv', 'w') as f:
writer = csv.writer(f)
for u in users:
writer.writerow([u.id,u.name,u.fllwr])
print(users[1].id,users[1].name,users[1].fllwr)
import os
os.system('spd-say "your program has finished"')
# import pandas as pd
# labels=['ID','Handle','#Followers']
# df=pd.DataFrame.from_records(users)
# print(df.head())
# with open('retUsrs.txt','w') as f:
# for u in range(len(users)):
# f.write(str(users[u])+' ')
# f.write(str(usrname[u])+' ')
# f.write(str(fllwrCnt[u])+'\n')
#
# print(len(users))
#
# print(json.dumps(tweets[0],indent=2))