Skip to content

Commit

Permalink
fixed up some output and long code lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew A. Russell committed Jan 28, 2011
1 parent 8e52435 commit d2e097c
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions recipe__visualize_rt_graph_graphviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,18 @@
import networkx as nx
from recipe__create_rt_graph import create_rt_graph

# Your query
Q = sys.argv[1]

# How many pages of data to grab for the search results
NUM_PAGES = 5

# How many search results per page
RESULTS_PER_PAGE = 100

# Writes out a DOT language file that can be converted into an
# image by Graphviz

def write_dot_output(g, out_file):

if not os.path.isdir('out'):
os.mkdir('out')

try:
nx.drawing.write_dot(g, os.path.join('out', out_file + ".dot"))
print >> sys.stderr, 'Data file written to: %s' % os.path.join(os.getcwd(), 'out', out_file + ".dot")
print >> sys.stderr, 'Data file written to: %s' % \
os.path.join(os.getcwd(), 'out', out_file + ".dot")
except ImportError, e:

# Help for Windows users:
Expand Down Expand Up @@ -56,7 +49,7 @@ def write_dot_output(g, out_file):

# How many pages of data to grab for the search results

NUM_PAGES = 5
MAX_PAGES = 5

# How many search results per page

Expand All @@ -65,9 +58,13 @@ def write_dot_output(g, out_file):
# Get some search results for a query

twitter_search = twitter.Twitter(domain='search.twitter.com')

search_results = []
for page in range(1,NUM_PAGES):
search_results.append(twitter_search.search(q=Q, rpp=RESULTS_PER_PAGE, page=page))
for page in range(1,MAX_PAGES+1):

search_results.append(
twitter_search.search(q=Q, rpp=RESULTS_PER_PAGE, page=page)
)

all_tweets = [tweet for page in search_results for tweet in page['results']]

Expand All @@ -77,5 +74,9 @@ def write_dot_output(g, out_file):

# Write Graphviz output

f = write_dot_output(g, OUT)
print >> sys.stderr, 'Try this: $ dot -Tpng -O%s %s.dot' % (OUT, OUT,)
if not os.path.isdir('out'):
os.mkdir('out')

f = write_dot_output(g, os.path.join(os.getcwd(), 'out', OUT))
print >> sys.stderr, \
'Try this on the DOT output: $ dot -Tpng -O%s %s.dot' % (OUT, OUT,)

0 comments on commit d2e097c

Please sign in to comment.