-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcreate_random_followers_graph.py
40 lines (37 loc) · 1.15 KB
/
create_random_followers_graph.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
# -*- coding: utf-8 -*-
__author__ = "Moses A. Boudourides & Sergios T. Lenis"
__copyright__ = "Copyright (C) 2015 Moses A. Boudourides & Sergios T. Lenis"
__license__ = "Public Domain"
__version__ = "1.0"
import networkx as nx
def create_random_followers_graph(followers_list,fil=None):
'''Creates a random_followers_graph with nodes the followers_list'''
if fil==None:
fil='friendship_graph.graphml'
n=len(followers_list)
G=nx.gnc_graph(n)
F=G.__class__()
mapping_f={}
for i,v in enumerate(followers_list):
mapping_f[i]=v
for edg in G.edges(data=True):
F.add_edge(mapping_f[edg[0]],mapping_f[edg[1]],attr_dict=edg[2])
for i in G.nodes():
att=G.node[i]
F.add_node(mapping_f[i], attr_dict=att)
nx.write_graphml(F,fil)
# return F
def read_user_list(filename):
ll=[]
f=open(filename)
for lin in f:
# print lin.strip()
ll.append(lin.strip())
return ll
# followers_list=['a','b','c','d','e']
# F=create_random_followers_graph(followers_list)
# print F.edges()
# print F.nodes()
user_list=read_user_list('user_list.txt')
# F=
create_random_followers_graph(user_list)