Created
February 25, 2009 17:12
-
-
Save drewconway/70288 to your computer and use it in GitHub Desktop.
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
def snowball_search(network,twitter_api,seed_user,cur_round): | |
# Snowball uses create_egonet to generate new structure | |
users=nodes_at_degree(network,cur_round) # Get all the users at the current round degree | |
for u in users: | |
time.sleep(5) # Wait five seconds in between to not hammer Twitter servers (H/T: @amyiris) | |
search_results=create_egonet(twitter_api,u) | |
network=NX.compose(network,search_results) | |
return network | |
def create_egonet(twitter_api,seed_user): | |
# Function for created a directed ego-net object from inital seed Twitter user | |
egonet=NX.DiGraph() | |
# Get friend data. NOTE: we are restricted to only adding out-degree | |
ego_friends=twitter_api.GetFriends(seed_user) | |
# Create ego's edge list | |
friend_ebunch=[(seed_user,str(u.screen_name)) for u in ego_friends] | |
# Add edges | |
egonet.add_edges_from(friend_ebunch) | |
return egonet | |
def nodes_at_degree(network,degree): | |
# Get nodes to perform round k search on | |
d=network.degree(with_labels=True) | |
d=d.items() | |
return [(a) for (a,b) in d if b==degree] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment