Open SamJingZhao opened 10 years ago
Hi - In the source code checkout, twitterutil.py is in the same directory as the_tweetharvest_timeline.py file, and as long as you are trying to run the script the_tweetharvcest_timeline.py from its working directory, everything should work fine. e.g. in a terminal, you would navigate to the python_code directory and then type "python the_tweetharvest_timeline.py" along with additional arguments.
The only reason you should get that import error is if you are trying to run the code from some other directory. Can you give that a shot (and provide more detail about how you are trying to run the script) if that doesn't help?
I'd also highly recommend watching these videos - https://vimeo.com/channels/MiningTheSocialWeb - which show you how to get started with the 2nd Edition virtual machine, which provides a much better/simpler coding experience in comparison if that's something you're willing to consider. The 2nd Edition repo is here if you want to take a look - https://github.com/ptwobrussell/Mining-the-Social-Web-2nd-Edition
Dear Matthew, I just import your document of Chapter 5 into iPython notebook, so do that means it in the other directory? I really love the 2nd Edition, why I am still learning the 1st Edition as many great examples in Chapter 5 of 1st Edition are not in the 2nd Edition. I will go to watch the videos, many thanks, I appreciate your support!
@SamJingZhao - Check out Chapter 9 of the 2nd Edition, which is linked off of its main GitHub repo page as a viewable notebook here - https://rawgithub.com/ptwobrussell/Mining-the-Social-Web-2nd-Edition/master/ipynb/html/Chapter%209%20-%20Twitter%20Cookbook.html
I think that the majority of the "good stuff" from Chapter 5 in the 1E is in that notebook in a much more consumable fashion, so you might have some good luck with it.
So it sounds like you are running IPython Notebook with the 1E code? If this is the case, then all you should have to do if you are working in IPython Notebook is have the ancillary files like twitter__util.py in the same directory that your Chapter 5 IPython notebook file is at so that you can execute it.
Alternatively (but a less preferred method) is that you could just open up files like twitter__util.py and copy/paste in the code into a notebook cell, execute it, and then it would be as though you have those functions available to you, and you wouldn't even need to import them.
Does that all make sense?
Let me know if this works for you. I want to make sure that you're taken care of and happy. I may have to sign off till the morning pretty soon, but I will check back on you in the AM. If you don't get this sorted by them, I will create you a custom Chapter 5 notebook with everything in it that you need so that you don't have to deal with the import errors, but try my advice in the meanwhile and see if it helps.
Dear Matthew, Sorry for my late reply, over night's of learning this book, I am almost sick and didn't reply you last night. Which example in Chapter 5 I need and I didn't found in the 2nd Edition is Example 5-12. Finding the tweets that have been retweeted most often (the_tweet_count_retweets_by_others.py)
I am hoping to using these example for analyzing how tweets impact world democracy. Could you give me suggestions or help me for these coding in the new API system? Many thanks. Jing
I believe that all of the examples that you're interested in are in the Twitter Cookbook that you can find here - https://rawgithub.com/ptwobrussell/Mining-the-Social-Web-2nd-Edition/master/ipynb/html/Chapter%209%20-%20Twitter%20Cookbook.html
Take a look at that and let me know if you think it has what you're looking for. The recipes are designed to be pretty easy to compose (sort of like lego building blocks) so if you are already doing a little bit of programming in Python, I think you'll be able to put them together pretty easily. Let me know, though, if this isn't what you're looking for.
You may also find this wiki page generally helpful that provides a full catalog of all numbered examples from the 2nd Edition - https://github.com/ptwobrussell/Mining-the-Social-Web-2nd-Edition/wiki/Numbered-Examples
Example 5-3. Harvesting tweets from a user or public timeline (the_tweet__harvest_timeline.py)
ImportError Traceback (most recent call last)