Anonymous user
Twitter: Difference between revisions
→Suggested exercises
imported>Jesstess |
imported>Jesstess |
||
Line 33:
* Get experience reading other people's code.
==Steps==
=== 1. Understand <code>search</code> ===
# Run <code>python twitter_api.py --search</code> with various search terms, e.g.
#* <code>python twitter_api.py --search=Python</code>
#* <code>python twitter_api.py --search="Red Sox"</code>
# Read through the <code>search</code> function in <code>twitter_functions.py</code>.
# Trace through the logic in <code>twitter_api.py</code> that turns the <code>--search</code> command line option into a call to <code>search</code>.
=== 2. Understand <code>trendingTopics</code> ===
# Run <code>python twitter_api.py --trending-topics</code>
# Read through the <code>trendingTopics</code> function in <code>twitter_functions.py</code>.
# Trace through the logic in <code>twitter_api.py</code> that turns the <code>--trending-topics</code> command line option into a call to <code>search</code>.
#* What are the <code>optparse</code> differences between the logic for <code>--search</code> and the logic for <code>--trending-topics</code>?
=== 3. Implement <code>userTweets</code> ===
# Using the <code>search</code> and <code>trendingTopics</code> functions as a reference, implement <code>userTweets</code> in <code>twitter_functions.py</code>.
This function should print recent tweets by the username provided on the command line.
You may find the <code>twitter.Api()</code> function <code>GetUserTimeline()</code> helpful.
To test this function, at the command line run
<pre>python twitter_api.py -u <username></pre>
For example,
<pre>python twitter_api.py -u bostonpython</pre>
=== 4. Implement <code>trendingTweets</code> ===
# Using the <code>search</code> and <code>trendingTopics</code> functions as a reference, implement <code>trendingTweets</code> in <code>twitter_functions.py</code>.
=== Bonus material ===
<ul>
Line 39 ⟶ 78:
Customize how tweets are displayed. Look at the <code>Status</code> and <code>User</code> classes in the [http://code.google.com/p/python-twitter/source/browse/twitter.py| Twitter code] for inspiration; options include the URL for the tweet, how many followers the sender has, the location of the sender, and if it was a retweet.
</li>
<li>[Long] A lot of the Twitter API requires that you be authenticated. Examples of actions that require authentication include: posting new tweets, getting a user's followers, getting private tweets from your friends, and following new people.
Line 62 ⟶ 88:
</li>
</ul>
|