Tweepy: Twitter Python Library
return to DevTwitter or DevPythonTweepy Home: http://pypi.python.org/pypi/tweepy/
Tweepy Docs: http://packages.python.org/tweepy/html/api.html
One of the shortcomings of the Tweepy docs, which otherwise used to be excellent, is the absence of a simple detail of various objects it uses (at least at the present time). Here's a simple dissection of the status, user, and search result objects.
Note: the objects are converted to dicts for display purposes. In using the object, the syntax would be something like status_object.id.
Code
To retrieve and display objects (these methods do not require oauth)# imports import tweepy from pprint import pprint # user timeline screen_name = 'klenwell' public_tweets = tweepy.api.user_timeline(screen_name) status_object = public_tweets[0] user_object = status_object.user # search search_terms = '"hello world"' rpp=25 result_list = tweepy.api.search(search_terms, rpp=rpp, lang='en') search_result_object = result_list[0] # print results pprint(status_object.__getstate__()) pprint(user_object.__getstate__()) pprint(search_result_object.__getstate__())
Objects
Status
{'author': <tweepy.models.User object at 0x908dbac>,
'contributors': None,
'coordinates': None,
'created_at': datetime.datetime(2010, 11, 21, 17, 2, 36),
'favorited': False,
'geo': None,
'id': 6392043970494464L,
'id_str': u'6392043970494464',
'in_reply_to_screen_name': None,
'in_reply_to_status_id': None,
'in_reply_to_status_id_str': None,
'in_reply_to_user_id': None,
'in_reply_to_user_id_str': None,
'place': None,
'retweet_count': None,
'retweeted': False,
'source': u'klenwell',
'source_url': u'http://klenwell.com/',
'text': u'appswell is a google app engine prototype application: http://bit.ly/appswell',
'truncated': False,
'user': <tweepy.models.User object at 0x908dbac>}User
{'contributors_enabled': False,
'created_at': datetime.datetime(2010, 4, 4, 16, 14, 59),
'description': None,
'favourites_count': 0,
'follow_request_sent': False,
'followers_count': 3,
'following': True,
'friends_count': 3,
'geo_enabled': False,
'id': 129532284,
'id_str': u'129532284',
'lang': u'en',
'listed_count': 1,
'location': None,
'name': u'klenwell',
'notifications': False,
'profile_background_color': u'C0DEED',
'profile_background_image_url': u'http://s.twimg.com/a/1288907344/images/themes/theme1/bg.png',
'profile_background_tile': False,
'profile_image_url': u'http://s.twimg.com/a/1288907344/images/default_profile_0_normal.png',
'profile_link_color': u'0084B4',
'profile_sidebar_border_color': u'C0DEED',
'profile_sidebar_fill_color': u'DDEEF6',
'profile_text_color': u'333333',
'profile_use_background_image': True,
'protected': False,
'screen_name': u'klenwell',
'show_all_inline_media': False,
'statuses_count': 121,
'time_zone': None,
'url': None,
'utc_offset': None,
'verified': False}Search Result
{'created_at': datetime.datetime(2010, 11, 25, 17, 48, 52),
'from_user': u'MayeYelverton',
'from_user_id': 176979953,
'from_user_id_str': u'176979953',
'geo': None,
'id': 7853239424786432L,
'id_str': u'7853239424786432',
'iso_language_code': u'en',
'metadata': {u'result_type': u'recent'},
'profile_image_url': u'http://a2.twimg.com/profile_images/1158133250/799698684gsgsgrsfds_normal.png',
'source': u'web',
'text': u'Hello world! http://order-funeral-flowers.org/hello-world/',
'to_user_id': None,
'to_user_id_str': None}
[There are no comments on this page]