blackandgreen.pyをgithubに上げてみた
前から作って放置してた、
投稿専用のtwitterクライアント、blackandgreenをcommitしてきました。
https://github.com/tkscotte/blackandgreen
ソースはこちら↓
# /usr/bin/python # -*- coding: utf-8 -*- import tweepy import sys from PySide.QtCore import * from PySide.QtGui import * # 取得してきたキー/シークレットキーを""" """内のhogeと置き換えます consumer_key = """hoge""" consumer_secret = """hoge""" access_key = """hoge""" access_secret = """hoge""" class Tweet(QDialog): def __init__(self, parent = None): super(Tweet, self).__init__(parent) # QLineEditで入力欄作成 # QPudhButtonで押しボタンを作成します self.word = QLineEdit("Please write your tweet") self.button = QPushButton("Upload") self.exit = QPushButton("Exit") # QVBoxLayoutは垂直にオブジェクトを配置します layout = QVBoxLayout() layout.addWidget(self.word) layout.addWidget(self.button) layout.addWidget(self.exit) self.setLayout(layout) # クリック後の動作先を設定します self.button.clicked.connect(self.twit) self.exit.clicked.connect(self.exited) def twit(self): try: # def __init__で入力させた文章を、twitt変数に入れます twitt = self.word.text() # 文字が入力されていない、また140文字以上の場合はダイアログを出します if 0==len(twitt) and 141>=len(twitt): label = QLabel("Sorry,Can't upload your tweet...") label.show() app.exec_() sys.exit() # OAuth認証が行われ、ツイートが送信されます else: auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_key, access_secret) api = tweepy.API(auth_handler=auth) api.update_status(twitt) except Exception: label = QLabel("Sorry,Can't run a program...") label.show() app.exec_() sys.exit() def exited(self): sys.exit() def main(): # Qtのアプリケーションを作成します app = QApplication(sys.argv) # フォームを作成、表示します tweet = Tweet() tweet.show() # Qtのメインループを開始します sys.exit(app.exec_()) if __name__ == '__main__': main()