Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
64 lines (41 sloc) 1.53 KB
# -*- coding: utf-8 -*-
import sys
import json
import twitter
import networkx as nx
from recipe__get_rt_origins import get_rt_origins
def create_rt_graph(tweets):
g = nx.DiGraph()
for tweet in tweets:
rt_origins = get_rt_origins(tweet)
if not rt_origins:
for rt_origin in rt_origins:
g.add_edge(rt_origin.encode('ascii', 'ignore'),
tweet['from_user'].encode('ascii', 'ignore'),
{'tweet_id': tweet['id']}
return g
if __name__ == '__main__':
# Your query
Q = ' '.join(sys.argv[1])
# How many pages of data to grab for the search results
# How many search results per page
# Get some search results for a query
twitter_search = twitter.Twitter(domain='')
search_results = []
for page in range(1,MAX_PAGES+1):
search_results.append(, rpp=RESULTS_PER_PAGE, page=page)
all_tweets = [tweet for page in search_results for tweet in page['results']]
# Build up a graph data structure
g = create_rt_graph(all_tweets)
# Print out some stats
print >> sys.stderr, "Number nodes:", g.number_of_nodes()
print >> sys.stderr, "Num edges:", g.number_of_edges()
print >> sys.stderr, "Num connected components:",
print >> sys.stderr, "Node degrees:", sorted(