Skype + Python = Skype4Py

この記事では、Skype APIのすばらしい拡張機能であるSkype4Pyについて知りたいと思います。 これを使用して、実際にskypeに接続し、2、3行のコードを記述した後、開発者がしていないことを実装できます。



約2か月前、Googleコードでmoc-trayと呼ばれるプロジェクトを見つけました。 これはgtk2-perlで書かれたプログラムであり、その意味は、トレイにハングアップし、優れたコンソールプレーヤーmocpの主な機能にアクセスするためのコンテキストメニューを表示することです 。 試してみて、現在の曲をSkypeのステータスとして表示することにしました。

すぐに言ってやった。

バックグラウンドでPython-status-scriptを起動するためのpearlプログラムの行が完了しました。 ああ、まあ、スクリプト自体:



 #!/usr/bin/env python # Skymoc. # # Python script to show current song title in skype status import time import commands import Skype4Py #  ,       # ASCII decoding error: ordinal not in range(128) #   -    en_US.UTF-8 reload(sys) sys.setdefaultencoding('utf-8') # Callback     def OnAttach(status): print "API Attachment status: %s" % skype.Convert.AttachmentStatusToText(status) attached = False #   if status == Skype4Py.apiAttachAvailable: while not attached: try: #     Public API allowed programs -  skype.Attach() attached = True #   - ,  ,     except: pass # Callback    def OnUserStatus(status): print "Current status: %s" % status skype = Skype4Py.Skype() #   skype.OnAttachmentStatus = OnAttach skype.OnUserStatus = OnUserStatus print 'Connecting to skype..' #  skype.Attach(Wait=False) profile = skype.CurrentUserProfile mocpSongTitle = '' while True: #  5  ,     time.sleep(5) (stat, currTitle) = commands.getstatusoutput('mocp -Q %title') if currTitle != mocpSongTitle: if currTitle != '': mocpSongTitle = currTitle profile.MoodText = mocpSongTitle else: profile.MoodText = ':-)'
      
      







ご覧のとおり、すべてが非常に簡単です。 少し時間がかかりました。 フットボールがあり、家で試合を見たくなかったのと同時に、重要なチャットメッセージを受け取らなければなりませんでした。 彼らは私の電話用のSkypeクライアントをまだ発明していないので、メールでメッセージを送信することにしました(電話の電子メールには良いクライアントがいます)。 送信者とテキストがメールに送信される着信メッセージにコールバックを設定することにより、すべてが20分で決定されました。



 #   def OnNotify(var): print "OnNotify: %s" % var def OnMessageStatus(chat, status): # ? ! if status == 'RECEIVED': # DynDns.org, port forwarding -     ! prompt = os.popen('echo "%s" | mail -s "%s" %s' % (chat.Body, "%s via Skype" % chat.Sender.FullName, 'example@gmail.com'), 'w') sent = prompt.close() print "Sent status: %s" % sent skype = Skype4Py.Skype() skype.OnAttachmentStatus = OnAttach skype.OnNotify = OnNotify # Callback    skype.OnMessageStatus = OnMessageStatus
      
      







さて、私は2つのSkypeクライアントを立ち上げ、一方から他方へ、そしてメールでメッセージを書きました。 確かに、その夜、私はそのメッセージを待ちませんでした。 しかし、翌日、彼らは私にメールを書きました:)この手紙が私の人生を変えることを願っています。



Skype4Pyドキュメント: http ://skype4py.sourceforge.net/doc/html/



頑張って



All Articles