def vk_graph(my_id=57573111):
    appid = '5989878'
    login = '******'
    password = '******'
    session = vk.AuthSession(appid, login, password, scope='friends')
    vk_api = vk.API(session)
    mygraph = MyGraph()
    me = vk_api.users.get(user_ids=my_id, fields='city,photo_400_orig,domain')
    mygraph.add_single_node(0, info=me)
    my_friends_ids = vk_api.friends.get(user_id=my_id)
    my_friends_full = vk_api.friends.get(user_id=my_id,
                                         fields='city,photo_400_orig,domain')
    active_friends = [my_id]
    counter = 1
    # print my_friends_full uncomment for info
    for friend in my_friends_full:
        if friend.get('deactivated') == None:
            active_friends.append(friend.get('user_id'))
            mygraph.add_single_node(active_friends.index(
                friend.get('user_id')),
                                    info=friend)
    mutual = vk_api.friends.getMutual(source_uid=my_id,
                                      target_uids=active_friends)
    for m in mutual:
        source = m.get('id')
        source_id = active_friends.index(source)
        print source_id
        mygraph.add_single_edge(0, source_id, weight=1)
        for target in m.get('common_friends'):
            if target in active_friends:
                target_id = active_friends.index(target)
                mygraph.add_single_edge(source_id, target_id, weight=1)
    return mygraph
Ejemplo n.º 2
0
def load():
    GRAPH_COUNT = 8
    graphs = []
    for graph_num in range(5, 6):
        print 'loaded %d' % graph_num
        graphs.append(Graph.Read_GraphML('graph%d.graphml' % graph_num))
    graphs_return = []
    # CHANGE HERE FOR ALL GRAPHS
    # graph = graphs[2]
    for graph in graphs:
        mygraph = MyGraph()
        count = 0
        for vertex in graph.vs:
            mygraph.add_single_node(count, graphmlid=vertex["id"])
            edges = graph.es.select(_source=count)
            for edge in edges:
                source, target = edge.tuple
                mygraph.add_single_edge(source, target, weight=1)
            count += 1
        graphs_return.append(mygraph)
    print graphs_return
    return graphs_return