wxPythonでtwitterのタイムライン表示
Pythonのtwitterライブラリのtwitter-pythonとwxPythonを組み合わせてタイムラインを表示させてみた。
あとはpostする機能がつけば簡易なクライアントになりそう。
使うにはソース中のusername,passwordにユーザ名、パスワードを代入して実行する。
# coding: utf-8 # - twitter-python # - wxPython # でタイムラインをリスト表示 import twitter import wx import datetime username = "" password = "" if username == "" or password == "": print "username and password is required. edit source and fill variable `username' and `password'!" import sys sys.exit() class Frame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, "timeline", size=(600,500)) self.list = wx.ListCtrl(self, -1, style=wx.LC_REPORT) self.api = twitter.Api(username, password) widths = [100, 300, 100] for i,c in enumerate([u"ユーザ", u"tweet", u"日付"]): self.list.InsertColumn(i, c) self.list.SetColumnWidth(i, widths[i]) self.update(None) self.timer = wx.Timer(self) self.timer.Start(1 * 60*1000) self.Bind(wx.EVT_TIMER, self.update) def update(self, event): self.list.DeleteAllItems() statuses = self.api.GetFriendsTimeline() for s in statuses: # datetime format d = datetime.datetime.strptime(s.created_at, "%a %b %d %H:%M:%S +0000 %Y") d = d.strftime("%Y/%m/%d %H:%M:%S") item = s.user.screen_name, s.text, d self.list.Append(item) if __name__ == '__main__': app = wx.PySimpleApp() Frame().Show() app.MainLoop()