Last active
January 2, 2016 02:49
-
-
Save yuitest/8239872 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
from __future__ import unicode_literals, print_function | |
import Skype4Py | |
import sys | |
import subprocess | |
from datetime import datetime, timedelta | |
class SkypeAutoCallStopper(object): | |
def __init__(self): | |
skype = Skype4Py.Skype(Transport='x11') | |
skype.Attach() | |
self._skype = skype | |
@property | |
def skype(self): | |
return self._skype | |
@skype.setter | |
def skype(self, value): | |
self._skype = value | |
def latest_chat(self): | |
return sorted( | |
list(self.skype.Chats), | |
key=lambda x: x.ActivityDatetime, reverse=True)[0] | |
@classmethod | |
def recent_talk_handles(self, chat): | |
now = datetime.now() | |
short_time_ago = now + timedelta(minutes=-10) | |
recent_message_handles = [ | |
message.FromHandle | |
for message in chat.Messages | |
if short_time_ago <= message.Datetime <= now | |
] | |
return tuple(recent_message_handles) | |
def placecall(self, name): | |
# Skype4Py の PlaceCall にバグがあるので無茶な try-catch | |
try: | |
self.skype.PlaceCall(name) | |
except ValueError: | |
pass | |
self.skype.ResetCache() | |
self.skype = Skype4Py.Skype(Transport='x11') | |
self.skype.Attach() | |
def disconnect_call(self, remains=()): | |
for call in self.skype.ActiveCalls: | |
if call.PartnerHandle in remains: | |
continue | |
call.Finish() | |
def main(self): | |
skype = self.skype | |
target = self.latest_chat() | |
remain_handles = self.recent_talk_handles(target) | |
self.placecall(target.Name) | |
self.disconnect_call(remains=remain_handles) | |
if __name__ == '__main__': | |
SkypeAutoCallStopper().main() |
キャッシュクリアがうまくできてなかったため、
自分自身を subprocess で呼ぶことでキャッシュクリアする、変な作りになってる。
バージョンアップした。
最新のチャットの、 10 分以内の会話から、残すユーザを決定する。
メモ: skype.Mute = True
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
スカイプのグループ通話を瞬時に切るアレ。