twitterでいろいろ作業ログを残そうと思うんだが、専用クライアントを使うんではどうしても一手間余分に掛かってたぶんそのうち飽きる。
これもATOKでやれればメモ帳でもブラウザの検索バーでもテキストを打てるところがあればPOSTできるよなーということでやってみた。
書き込む
最新のupdateを取得
うまく書けてる
#!-*- coding:utf-8 -*- #ATOK2009プラグイン twitterクライアント import urlparse import urllib2 import urllib from xml.etree.ElementTree import fromstring username = 'username' password = 'password' realm = 'Twitter API' url_update = 'http://twitter.com/statuses/update.xml' url_timeline = 'http://twitter.com/statuses/user_timeline.xml' def open(target_url): url = urlparse.urlparse(target_url) handler = urllib2.HTTPBasicAuthHandler() handler.add_password( realm, url.hostname, username, password ) return urllib2.build_opener(handler) def update(message): opener = open(url_update) data = urllib.urlencode( { 'status': message.encode('utf-8') } ) opener.open(url_update, data) def getTimeLine(): opener = open(url_timeline) r = opener.open(url_timeline) elem = fromstring(r.read()) statuses = elem.findall('.//status') texts = [] for status in statuses: text = status.findtext('./text') texts.append(text) return texts def atok_plugin_run_process( a_request_data ): result_data = {} candidate_array = [] str = a_request_data[ 'composition_string' ] if str == u'tl': #user_timeline texts = getTimeLine() for text in texts: candidate_array.append( { 'hyoki' : text } ) else: #update candidate_array.append( { 'hyoki' : u'[送信確定]', 'alternative': str } ) result_data[ 'candidate' ] = candidate_array return result_data def atok_plugin_run_callback( a_data ): str = a_data['composition_string'] if str == u'tl': pass else: update(str) def test(): """ print getTimeLine() """ pass if __name__ == '__main__': test()