This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
def get_player_profiles(player_list): | |
# Returns a dict of player profile URLs to be used in the next step | |
# Dict will hold player profile pages indexed by player name | |
player_profile_urls=dict.fromkeys(player_list) | |
for n in player_list: | |
names=n.split(' ') | |
# Search for the player names at NFL.com to get their individual player profiles, which contain the | |
# data we ultimately want. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import csv | |
def get_players(path): | |
# Returns a list of player names from CSV file | |
reader=csv.reader(open(path,'U'),delimiter=',') | |
''' | |
players=[] | |
row_num=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
""" | |
Experiments for growing fractal networks | |
Created by Drew Conway on 2009-05-19. | |
Copyright (c) 2009. All rights reserved. | |
""" | |
import sys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
""" | |
exploded_view_3d.py | |
The purpose of this script is to create an 'exploded view' | |
of a network in 3D using hierarchical clustering of geodesic | |
distances in NetworkX and UbiGraph. | |
This script is intended as an illustrative proof of concept |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
""" | |
TwitterEgoBuilder.py | |
Created by Drew Conway on 2009-02-23. | |
Copyright (c) 2009. All rights reserved. | |
The purpose of this script is to generate a | |
NetworkX DiGraph object based on the snowball |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
counts = dict((k, F.count(k)) for k in set(F)) | |
counts_items=counts.items() | |
counts_items=[(b,a) for (a,b) in counts_items] | |
counts_items.sort() | |
counts_items.reverse() | |
for i in counts_items: | |
print str(i[0])+' of your friends are already following '+i[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N=K.neighbors('your_twitter_id') | |
F=[] | |
for u in N: | |
D=K.neighbors(u) | |
for i in D: | |
if N.count(i)<1 and i is not 'your_twitter_id': | |
F.append(i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from networkx import core | |
kcores=core.find_cores(G) | |
core_items=kcores.items() | |
two_core=[(a) for (a,b) in core_items if b>1] | |
K=subgraph(G,two_core) | |
info(K) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from networkx import * | |
import os | |
os.chdir('/Where/You/Stored/TheData/File/') | |
G=read_edgelist('your_net.edgelist',delimiter='\t',create_using=Graph(),nodetype=str) | |
info(G) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Store network data as plain text file to be analyzed later | |
twitter_net._name=seed+'_k'+str(k) # Name the network after the seed and the number of snowball rounds | |
NX.write_edgelist(twitter_net,path='your_net.edgelist',delimiter='\t') |