From 692d5054b96ed8e93ce20ad9387e193206e64d90 Mon Sep 17 00:00:00 2001 From: Josh Roesslein Date: Sat, 8 Aug 2009 15:44:50 -0500 Subject: [PATCH] Added tutorial 3. Still a work in progress. --- tutorial/t0.py | 5 +++++ tutorial/t2.py | 2 +- tutorial/t3.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tutorial/t3.py diff --git a/tutorial/t0.py b/tutorial/t0.py index 363ac11..a0741ee 100644 --- a/tutorial/t0.py +++ b/tutorial/t0.py @@ -15,6 +15,11 @@ You can then run the tutorial like such: python t1.py +Tutorials: + + 1 -- Authentication + 2 -- API + Author: Joshua Roesslein """ diff --git a/tutorial/t2.py b/tutorial/t2.py index 75d85a9..208b6fa 100644 --- a/tutorial/t2.py +++ b/tutorial/t2.py @@ -1,5 +1,5 @@ import tweepy -from t1 import * +from t1 import oauth_auth """ Tutorial 2 -- API diff --git a/tutorial/t3.py b/tutorial/t3.py new file mode 100644 index 0000000..c92d865 --- /dev/null +++ b/tutorial/t3.py @@ -0,0 +1,44 @@ +import tweepy + +""" Tutorial 3 -- Models + +Tweepy uses a set of models to transfer data from the +Twitter API to your python application. The following +models are used... + + Status, User, DirectMessage, Friendship, + SavedSearch, SearchResult + +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. +""" + +""" +First let's create our own implementaion of Status. +""" +class MyStatus(tweepy.Status): + + def length(self): + """Return length of status text""" + return len(self.text) + +""" +We must now register our implementation of Status with tweepy. +""" +tweepy.models['status'] = MyStatus + +""" +Now to test out our new status model... +""" +s = tweepy.api.get_status(123) +print 'Length of status 123: %i' % s.length() + +""" +As you can see once you register your model with tweepy +it will be used for each API call. If you want to restore +the Status model to tweepy's implementation... +""" +tweepy.models['status'] = tweepy.Status + -- 2.25.1