Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys,codecs
- '''
- format emiter receiver contacts
- example: 5767599 242682935 4
- '''
- links={}
- i=0
- f=file("/dev/stdin")
- for line in f:
- i+=1
- #print line
- line=line.split(";");
- emiter=int(line[0])
- reciever=int(line[1])
- contacts=int(line[2])
- l=sorted([emiter,reciever])
- #rel_key='-'.join(map(str,l))
- rel_key=(l[0],l[1])
- di=0 if caller<callee else 1
- if not rel_key in links:
- links[rel_key]=[0,0]
- links[rel_key][di]+=contacts
- if i%1000000==0:
- print "read %i million contacts"%(i/1000000)
- print len(links),"relationships in dict"
- f.close()
- f=codecs.open("network-mutual-graph","w")
- f2=codecs.open("network-directed-graph","w")
- for link,contacs in links.iteritems():
- link=link.split('-')
- if contacts[0]==0:
- f2.write("%s %s %i \n"%(link[1],link[0],contacts[1]))
- elif contacts[1]==0:
- f2.write("%s %s %i \n"%(link[0],link[1],contacts[0]))
- else:
- f.write("%s %s %i %i \n"%(link[0],link[1],contacts[0],contacts[1]))
Add Comment
Please, Sign In to add comment