Commit dcabbc26 authored by Josh Roesslein's avatar Josh Roesslein
Browse files

Added tutorial 5.

parent 822db1a4
......@@ -14,11 +14,11 @@ models are used...
A nice feature of Tweepy is that you can extend or even provide
your own implementations of these models. Tweepy simply just sets
the attributes and returns back an instance of your model class.
This makes it easy to intergrate your ORM into Tweepy.
This makes it easy to integrate your ORM into Tweepy.
"""
"""
First let's create our own implementaion of Status.
First let's create our own implementation of Status.
"""
class MyStatus(tweepy.Status):
......
......@@ -20,7 +20,7 @@ except tweepy.TweepError, e:
"""
TweepError's can be casted to string format which will
give details as to what wents wrong.
give details as to what went wrong.
The main reasons an exception will be raised include:
-HTTP request to twitter failed
......
import tweepy
""" Tutorial 5 -- Cache
Tweepy provides a caching layer for frequently
requested data. This can help cut down on Twitter API
requests helping to make your application faster.
By default caching is disabled in API instances.
"""
"""
Let's create a new API instance with caching enabled.
Currently Tweepy just comes with an in-memory cache which
we will use for this demo.
"""
cached_api = tweepy.API(cache=tweepy.MemoryCache(timeout=120))
"""
Now we can use this API instance and any request that uses
'GET' will be cached for 120 seconds. If no timeout is specified
the default is 60 seconds.
Here is a demo using our new cached API instance...
"""
non_cached_result = cached_api.public_timeline()
cached_result = cached_api.public_timeline()
"""
The first request (non_cached_result) will require a trip
to the Twitter server. The second request (cached_result)
will be retrieved from the cache saving a trip to Twitter.
"""
""" Your own cache implementation
If you wish to use your own cache implementation just
extend the Cache interface class (tweepy/cache.py).
Then when you create your API instance pass it in.
"""
my_api = tweepy.API(cache=MyCache())
""" The End """
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment