Skip to content

Commit

Permalink
Fixes KeyError in retweet visualization example
Browse files Browse the repository at this point in the history
Fixes an issue where a search query may not return any results or not as
many results may exist as expected, which manifests as a KeyError
  • Loading branch information
ptwobrussell committed Jul 6, 2013
1 parent c87fae6 commit 16a0659
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion python_code/introduction__retweet_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ def get_rt_origins(tweet):
tweets = search_results['statuses']

for _ in range(5): # Get 5 more pages
next_results = search_results['search_metadata']['next_results']
try:
next_results = search_results['search_metadata']['next_results']
except KeyError, e: # No more results when next_results doesn't exist
break

# Create a dictionary from the query string params
kwargs = dict([ kv.split('=') for kv in next_results[1:].split("&") ])
Expand Down

0 comments on commit 16a0659

Please sign in to comment.