Tests and documentation

This commit is contained in:
Mike Helmick 2013-06-27 19:20:43 -04:00
parent 173adee4a6
commit 3c637ddc7d
6 changed files with 71 additions and 3 deletions

View file

@ -37,6 +37,7 @@ Usage
usage/basic_usage
usage/advanced_usage
usage/streaming_api
usage/special_functions
Twython API Documentation
-------------------------

View file

@ -0,0 +1,47 @@
.. special-functions:
Special Functions
=================
This section covers methods to are part of Twython but not necessarily connected to the Twitter API.
*******************************************************************************
HTML for Tweet
--------------
This function takes a tweet object received from the Twitter API and returns an string formatted in HTML with the links, user mentions and hashtags replaced.
.. code-block:: python
from twython import Twython
twitter = Twython(APP_KEY, APP_SECRET,
OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
user_tweets = twitter.get_user_timeline(screen_name='mikehelmick',
include_rts=True)
for tweet in user_tweets:
tweet['text'] = Twython.html_for_tweet(tweet)
print tweet['text']
The above code takes all the tweets from a specific users timeline, loops over them and replaces the value of ``tweet['text']`` with HTML.
So:
http://t.co/FCmXyI6VHd is a #cool site, lol! @mikehelmick should #checkitout. If you can! #thanks Love, @__twython__ https://t.co/67pwRvY6z9
will be replaced with:
<a href="http://t.co/FCmXyI6VHd" class="twython-url">google.com</a> is a <a href="https://twitter.com/search?q=%23cool" class="twython-hashtag">#cool</a> site, lol! <a href="https://twitter.com/mikehelmick" class="twython-mention">@mikehelmick</a> should <a href="https://twitter.com/search?q=%23checkitout" class="twython-hashtag">#checkitout</a>. If you can! <a href="https://twitter.com/search?q=%23thanks" class="twython-hashtag">#thanks</a> Love, <a href="https://twitter.com/__twython__" class="twython-mention">@__twython__</a> <a href="https://t.co/67pwRvY6z9" class="twython-url">github.com</a>
.. note:: When converting the string to HTML we add a class to each HTML tag so that you can maninpulate the DOM later on.
- For urls that are replaced we add ``class="twython-url"`` to the anchor tag
- For user mentions that are replaced we add ``class="twython-mention"`` to the anchor tag
- For hashtags that are replaced we add ``class="twython-hashtag"`` to the anchor tag
This function excepts two parameters: ``use_display_url`` and ``use_expanded_url``
By default, ``use_display_url`` is ``True``. Meaning the link displayed in the tweet text will appear as (ex. google.com, github.com)
If ``use_expanded_url`` is ``True``, it overrides ``use_display_url``. The urls will then be displayed as (ex. http://google.com, https://github.com)
If ``use_display_url`` and ``use_expanded_url`` is ``False``, short url will be used (t.co/xxxxx)

View file

@ -81,6 +81,7 @@ You'll want to extract the ``oauth_verifier`` from the url.
Django example:
.. code-block:: python
oauth_verifier = request.GET['oauth_verifier']
Now that you have the ``oauth_verifier`` stored to a variable, you'll want to create a new instance of Twython and grab the final user tokens