From dcabbc26c02d5b6b53946ab92c4217a180c8000c Mon Sep 17 00:00:00 2001 From: Josh Roesslein Date: Sat, 8 Aug 2009 16:32:52 -0500 Subject: [PATCH] Added tutorial 5. --- tutorial/t3.py | 4 ++-- tutorial/t4.py | 2 +- tutorial/t5.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 tutorial/t5.py diff --git a/tutorial/t3.py b/tutorial/t3.py index d5c166c..954e745 100644 --- a/tutorial/t3.py +++ b/tutorial/t3.py @@ -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): diff --git a/tutorial/t4.py b/tutorial/t4.py index 1ee052a..a59e2ec 100644 --- a/tutorial/t4.py +++ b/tutorial/t4.py @@ -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 diff --git a/tutorial/t5.py b/tutorial/t5.py new file mode 100644 index 0000000..0fed0e7 --- /dev/null +++ b/tutorial/t5.py @@ -0,0 +1,42 @@ +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 """ + -- 2.25.1