Skip to content

Instantly share code, notes, and snippets.

@yuitest
Last active January 2, 2016 02:49
Show Gist options
  • Save yuitest/8239872 to your computer and use it in GitHub Desktop.
Save yuitest/8239872 to your computer and use it in GitHub Desktop.
# 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()
@yuitest
Copy link
Author

yuitest commented Jan 3, 2014

スカイプのグループ通話を瞬時に切るアレ。

@yuitest
Copy link
Author

yuitest commented Jan 3, 2014

キャッシュクリアがうまくできてなかったため、
自分自身を subprocess で呼ぶことでキャッシュクリアする、変な作りになってる。

@yuitest
Copy link
Author

yuitest commented Jan 13, 2014

バージョンアップした。

最新のチャットの、 10 分以内の会話から、残すユーザを決定する。

@yuitest
Copy link
Author

yuitest commented Jan 13, 2014

メモ: skype.Mute = True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment