ptwobrussell / Mining-the-Social-Web

The official online compendium for Mining the Social Web (O'Reilly, 2011)
http://bit.ly/135dHfs
Other
1.21k stars 491 forks source link

Mining the Social Web, Second Edition #78

Open agarwalkushal25 opened 10 years ago

agarwalkushal25 commented 10 years ago

On pages 25-26, there is this code:

q = '#MentionSomeoneImportantForYou'

count = 100

search_results = twitter_api.search.tweets(q=q, count=count)

twitter_api is predefined and is working fine.

statuses = search_results['statuses']

for _ in range(5): print "Length of statuses", len(statuses) try: next_results = search_results['search_metadata']['next_results'] except KeyError, e: # No more results when next_results doesn't exist break

kwargs = dict([ kv.split('=') for kv in next_results[1:].split("&") ])

The last code throws an error that 'next_results' is not defined.

ptwobrussell commented 10 years ago

I may be missing something, but from briefly inspecting the code again, I'm having a hard time identifying how this could happen. If the code in the "try" block fails, then it should break you out of the loop, avoiding the line of code in question that references "next_results"

Are you sure that your indentation level is correct? I can't tell from what you pasted in if you're running the code from in the notebook as-is or if you've typed it in and may have inadvertently adjusted indent levels.

I can think about this some more, but just wanted to check back first on how you are executing the code.

On Jul 9, 2014, at 3:18 AM, agarwalkushal25 notifications@github.com wrote:

On pages 25-26, there is this code:

q = '#MentionSomeoneImportantForYou'

count = 100

search_results = twitter_api.search.tweets(q=q, count=count)

twitter_api is predefined and is working fine.

statuses = search_results['statuses']

for _ in range(5): print "Length of statuses", len(statuses) try: next_results = search_results['search_metadata']['next_results'] except KeyError, e: # No more results when next_results doesn't exist break

kwargs = dict([ kv.split('=') for kv in next_results[1:].split("&") ])

The last code throws an error that 'next_results' is not defined.

— Reply to this email directly or view it on GitHub.

Drlenita commented 9 years ago

I am totally lost, in trying to install a virtual machine. I do not know how to get to the screen, I follow until you get to step three on installing code on gitclone and goblin. I do not know how you get to that screen and get that code to run. I have osX on Mac. I installed github Please help!!1

ptwobrussell commented 9 years ago

The screen that you see there is called a terminal. If you are on OS X, you should have an app called Terminal that you can use for that, but if you have never worked on the command line ever before, it might be a bit awkward at first. Give it a shot and let me know if I can help further.

On Wed, Sep 10, 2014 at 9:35 AM, Drlenita notifications@github.com wrote:

I am totally lost, in trying to install a virtual machine. I do not know how to get to the screen, I follow until you get to step three on installing code on gitclone and goblin. I do not know how you get to that screen and get that code to run. I have osX on Mac. I installed github Please help!!1

— Reply to this email directly or view it on GitHub https://github.com/ptwobrussell/Mining-the-Social-Web/issues/78#issuecomment-55124072 .