You are on page 1of 2

C:\Users\Martn\Dropbox\itam m\4to sem\EDA\Grafos Python\Lo necesario para hacer la tarea de esponda\Lo necesario para hacer la tarea jueves, de esponda\grafoEDAmutuo.

py 23 de mayo de 2013 07:25 a. m.

#!/usr/bin/python import twitter import json import urllib2 import random import networkx as nx import matplotlib.pyplot as plt #def grafo ( usuario , Acces_token , Acces_token_secret , Consumer_key , Consumer_secret ): NF = nx.Graph () #La de Martin api1 = twitter.Api(consumer_key='quTG6z17Ayn0JtPRHJAvw', consumer_secret= 'geuNW3ZEmisBoo6ydLGBdT1BGDCOTohwsSbhWWl24' , access_token_key= '57800507-7m2umv9hn0kVoTlYrfAj0gTN9MIYBPo9xw09fqBOo' , access_token_secret= 'NU5Wc8FEel8mfwga4IUJZ3xcoYkg5vg2Z2dCj96J04E') #La de Marco #api2 = twitter.Api(consumer_key='qQJqOPxrGfaSvT8SeDvSgQ', consumer_secret='TbJ3JkgCUTETdzDZFZJyDpIp73F7rHDE6geIKdemjE' , access_token_key='32989403-qmgP4FcUilvWG6IGEvoXL5jg1d0TPULQ7aUCmkRS2' , access_token_secret='3tHUiDXA4tz52Zisa1An8nu1qsEqAT2espriSm4Vg') api2=twitter.Api(consumer_key='c28LCCRzNYkOowJh1L3Vw', consumer_secret= 'IwuJyEDV4ialzLBZQ0FxHTljkGkxpzzGsPoSpA0OBc' , access_token_key= '32989403-tefheETNbTEK3l7DKTe6n5Mor3BQhf8zeP7842bM' , access_token_secret= '9qcujqnnBdOCGxnWU2dxlxhMmIuYUk9QCV4saW2NY') #Este nos da quien sigue a nuestro usuario followers=twitter.User followers1=api1.GetFollowers() followers2=api2.GetFollowers() #Este nos da a quien le dio follow nuestro usuario following=twitter.User following1=api1.GetFriends(user = 'martinc_colin') following2=api2.GetFriends(user = 'marinisaac1') #Metemos todo dos matrices de IDs para checar si estan o no matfollowers1=list() for i in range(0,len(followers1)-1): matfollowers1.append(followers1[i].id) matfollowers2=list() for i in range(0,len(followers2)-1): matfollowers2.append(followers2[i].id) matfollowing1=list() for i in range(0,len(following1)-1): matfollowing1.append(following1[i].id) matfollowing2=list() for i in range(0,len(following2)-1): matfollowing2.append(following2[i].id) count=0 y=0 matres1=list() while (y<len(matfollowers1)-1): if (matfollowers1[y] in matfollowing1): matres1.append(followers1[y]) count=count+1 y=y+1 count=0 y=0
-1-

C:\Users\Martn\Dropbox\itam m\4to sem\EDA\Grafos Python\Lo necesario para hacer la tarea de esponda\Lo necesario para hacer la tarea jueves, de esponda\grafoEDAmutuo.py 23 de mayo de 2013 07:25 a. m.

matres2=list() while (y<len(matfollowers2)-1): if (matfollowers2[y] in matfollowing2): matres2.append(followers2[y]) count=count+1 y=y+1 y=0 count=0 matres3=list() while (y<len(matres1)-1): if (matres1[y] in matres2): matres3.append(matres1[y]) y=y+1 for r in range(0,len(matres3)-1): nodo=matres3[r].screen_name NF.add_node ( str ( nodo ) ) e1 = ( str ( "martinc_colin" ) , str ( nodo )) e2 = ( str ( "marinisaac1" ) , str ( nodo )) NF.add_edge (*e1 ) NF.add_edge (*e2 ) print( NF.nodes () ) print( NF.edges () ) matriz = nx.to_numpy_matrix ( NF , nodelist = NF.nodes () ) print( matriz ) nx.draw ( NF ) plt.savefig ("C:/grafoMutuo.png")

-2-

You might also like