kaakaa Blog

この世は極楽 空にはとんぼ

tweepyを使ってみた

URLを貼り付けるだけの簡単なお仕事。

Tweepyを使うまで
Twitter From the Command Line in Python Using OAuth

TweepyのAPI
API Reference — tweepy v1.4 documentation


とりあえず、search_users()で自分を検索してみる。

#!/usr/bin/env python

import sys
import tweepy
import inspect

CONSUMER_KEY = '****'
CONSUMER_SECRET = '****'
ACCESS_KEY = '****'
ACCESS_SECRET = '****'

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
users = api.search_users(sys.argv[1])

for p in inspect.getmembers(users[0]):
        print p


結果。

('__class__', )
('__delattr__', )
('__dict__', {'follow_request_sent': False, 'profile_use_background_image': True, 'contributors_enabled': False, 'id': 461961652, '_api': , 'verified': False, 'profile_image_url_https': u'https://si0.twimg.com/profile_images/2243152042/DSC03646_normal.jpg', 'profile_sidebar_fill_color': u'DDEEF6', 'profile_text_color': u'333333', 'followers_count': 18, 'protected': False, 'location': u'\u6a2a\u6d5c', 'default_profile_image': False, 'id_str': u'461961652', 'status': , 'utc_offset': None, 'statuses_count': 286, 'description': u'Engineer\u57a2\uff08private\u57a2\u2192 @kaakaa_hoe\uff09\u3068\u8a00\u3044\u306a\u304c\u3089\u3001\u30a2\u30a6\u30c8\u30d7\u30c3\u30c8\u306f\u307b\u3068\u3093\u3069\u306a\u304f\u30a4\u30f3\u30d7\u30c3\u30c8\u3070\u304b\u308a\u3002\u4ed5\u4e8b\u306fJava\u4f7f\u3063\u305f\u958b\u767a\u3057\u3066\u307e\u3059\u3002\u30d7\u30ed\u30b0\u30e9\u30e0\u521d\u3081\u3066\uff12\u5e74\u76ee\u3002Jenkins\u4f7f\u3044\u306b\u306a\u308a\u305f\u3044\u3002', 'friends_count': 76, 'profile_link_color': u'0084B4', 'profile_image_url': u'http://a0.twimg.com/profile_images/2243152042/DSC03646_normal.jpg', 'notifications': False, 'geo_enabled': False, 'profile_background_color': u'C0DEED', 'profile_background_image_url': u'http://a0.twimg.com/images/themes/theme1/bg.png', 'screen_name': u'kaakaa_hoe_prog', 'lang': u'ja', 'following': False, 'profile_background_tile': False, 'favourites_count': 89, 'name': u'kaakaa_hoe_prog', 'url': u'http://d.hatena.ne.jp/kaakaa_hoe/', 'created_at': datetime.datetime(2012, 1, 12, 11, 56, 51), 'profile_background_image_url_https': u'https://si0.twimg.com/images/themes/theme1/bg.png', 'time_zone': None, 'profile_sidebar_border_color': u'C0DEED', 'default_profile': True, 'is_translator': False, 'listed_count': 1})
('__doc__', None)
('__format__', )
('__getattribute__', )
('__getstate__', >)
('__hash__', )
('__init__', >)
('__module__', 'tweepy.models')
('__new__', )
('__reduce__', )
('__reduce_ex__', )
('__repr__', )
('__setattr__', )
('__sizeof__', )
('__str__', )
('__subclasshook__', )
('__weakref__', None)
('_api', )
('contributors_enabled', False)
('created_at', datetime.datetime(2012, 1, 12, 11, 56, 51))
('default_profile', True)
('default_profile_image', False)
('description', u'Engineer\u57a2\uff08private\u57a2\u2192 @kaakaa_hoe\uff09\u3068\u8a00\u3044\u306a\u304c\u3089\u3001\u30a2\u30a6\u30c8\u30d7\u30c3\u30c8\u306f\u307b\u3068\u3093\u3069\u306a\u304f\u30a4\u30f3\u30d7\u30c3\u30c8\u3070\u304b\u308a\u3002\u4ed5\u4e8b\u306fJava\u4f7f\u3063\u305f\u958b\u767a\u3057\u3066\u307e\u3059\u3002\u30d7\u30ed\u30b0\u30e9\u30e0\u521d\u3081\u3066\uff12\u5e74\u76ee\u3002Jenkins\u4f7f\u3044\u306b\u306a\u308a\u305f\u3044\u3002')
('favourites_count', 89)
('follow', >)
('follow_request_sent', False)
('followers', >)
('followers_count', 18)
('followers_ids', >)
('following', False)
('friends', >)
('friends_count', 76)
('geo_enabled', False)
('id', 461961652)
('id_str', u'461961652')
('is_translator', False)
('lang', u'ja')
('listed_count', 1)
('lists', >)
('lists_memberships', >)
('lists_subscriptions', >)
('location', u'\u6a2a\u6d5c')
('name', u'kaakaa_hoe_prog')
('notifications', False)
('parse', >)
('parse_list', >)
('profile_background_color', u'C0DEED')
('profile_background_image_url', u'http://a0.twimg.com/images/themes/theme1/bg.png')
('profile_background_image_url_https', u'https://si0.twimg.com/images/themes/theme1/bg.png')
('profile_background_tile', False)
('profile_image_url', u'http://a0.twimg.com/profile_images/2243152042/DSC03646_normal.jpg')
('profile_image_url_https', u'https://si0.twimg.com/profile_images/2243152042/DSC03646_normal.jpg')
('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'kaakaa_hoe_prog')
('status', )
('statuses_count', 286)
('time_zone', None)
('timeline', >)
('unfollow', >)
('url', u'http://d.hatena.ne.jp/kaakaa_hoe/')
('utc_offset', None)
('verified', False)


SearchResultオブジェクトは、けっこう色々なパラメータ持ってるのね。



sphinx使ってみたいな〜

tweetをドキュメント化しようか

twitter apiどうやって叩くんだろう

ってな流れでtweepy調べてた。
tweepy使えそうなので、そろそろ当初の目的であるsphinxに戻れそう。