forked from alexstorer/twittersauce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
processnetwork.py
38 lines (30 loc) · 1.07 KB
/
processnetwork.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
import json
fname = "iqssrtc_net.json"
f = open(fname)
d = json.load(f)
f.close()
namelookup = dict()
uidlookup = dict()
for k in d:
userd = d[k]
if type(userd) is type(dict()):
namelookup[userd['details']['screen_name']] = str(userd['details']['id'])
uidlookup[str(userd['details']['id'])] = str(userd['details']['screen_name'])
adjset = set(d[namelookup['iqssrtc']]["friends"]+d[namelookup['iqssrtc']]["followers"])
fw = open('iqssrtc_net.csv','w')
for k in d:
userd = d[k]
if type(userd) is type(dict()):
if userd["followers"] is not None:
for id in userd["followers"]:
if id in adjset:
source = uidlookup[str(id)]
dest = uidlookup[k]
fw.write(source+','+dest+'\n')
if userd["friends"] is not None:
for id in userd["friends"]:
if id in adjset:
dest = uidlookup[str(id)]
source = uidlookup[k]
fw.write(source+','+dest+'\n')
fw.close()