filename.py
# coding: utf-8
import sys
import Skype4Py
import pycurl
import urllib
import json
from io import BytesIO
argv1 = unicode (sys.argv[1], 'utf-8', 'ignore')
def GetChat (skype, topic):
for ct in skype.Chats:
if ct.Topic == topic:
return ct
def callSkype ():
skype = Skype4Py.Skype ()
skype.Attach ()
message = txt + argv3
chat = GetChat (skype, u"Skype chanel name")
chat.SendMessage (message)
def callCW ():
roomId = '123123123' # room id
url_message = 'https://xxxxxxxxxxxxxxxxrooms/' + roomId + '/messages'
url_members = 'https://xxxxxxxxxxxxxxxxrooms/' + roomId + '/members'
token = 'X-ChatWorkToken: 123123123123123123'
curl = pycurl.Curl()
curl.setopt(pycurl.HTTPHEADER, [token])
def getAllMembers ():
curl.setopt(pycurl.URL, url_members)
b = BytesIO()
curl.setopt(pycurl.WRITEFUNCTION, b.write)
curl.perform()
members = json.loads(b.getvalue())
msg = ""
for member in members:
msg += "[To:" + str(member["account_id"]) + "]"
return msg
txt = "[title]" + getAllMembers () + "[/title]" + argv1
message = "[info]" + txt + argv1 + "[/info]"
option = {'body': message}
curl.setopt(pycurl.URL, url_message)
curl.setopt(pycurl.POST, 1)
curl.setopt(pycurl.POSTFIELDS, urllib.urlencode(option))
curl.perform()
if __name__ == '__main__':
callSkype ()
callCW ()
Recommended Posts