Send messages to Skype and Chatwork in Python

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

Send messages to Skype and Chatwork in Python
Send email to multiple recipients in Python (Python 3)
How to use is and == in Python
How to generate permutations in Python and C ++
Send push notifications to iOS apps in Python
Try using ChatWork API and Qiita API in Python
Send Gmail in Python
To represent date, time, time, and seconds in Python
How to plot autocorrelation and partial autocorrelation in python
Convert timezoned date and time to Unixtime in Python2.7
Write tests in Python to profile and check coverage
[Python] How to sort dict in list and instance in list
To flush stdout in Python
Login to website in Python
Send email in Python (Outlook)
Stack and Queue in Python
Speech to speech in python [text to speech]
Unittest and CI in Python
How to develop in Python
Post to Slack in Python
Script to count and stop up to 5 seconds in Python in Blender
Try to make it using GUI and PyQt in Python
How to swap elements in an array in Python, and how to reverse an array.
Application to display and search local memos (diary) in Python
[Introduction to Udemy Python 3 + Application] 36. How to use In and Not
Send experiment results (text and images) to slack with Python
Display numbers and letters assigned to variables in python print
Tips for coding short and easy to read in Python
A standard way to develop and distribute packages in Python
Useful tricks related to list and for statements in Python
Comparison of how to use higher-order functions in Python 2 and 3
Introduction to Effectiveness Verification Chapters 4 and 5 are written in Python
Object-oriented in C: Refactored "○ ✕ game" and ported it to Python
How to execute external shell scripts and commands in python
Just try to receive a webhook in ngrok and python
How to log in to AtCoder with Python and submit automatically
[aws] Send and receive sqs messages
MIDI packages in Python midi and pretty_midi
Python 3.6 on Windows ... and to Xamarin.
Difference between list () and [] in Python
[Introduction to Python3 Day 1] Programming and Python
View photos in Python and html
Convert markdown to PDF in Python
Sorting algorithm and implementation in Python
How to collect images in Python
Send messages and images using LineNotify
How to use SQLite in Python
Manipulate files and folders in Python
About dtypes in Python and Cython
In the python command python points to python3.8
Assignments and changes in Python objects
Try to calculate Trace in Python
Check and move directories in Python
Ciphertext in Python: IND-CCA2 and RSA-OAEP
Hashing data in R and Python
How to use Mysql in python
How to wrap C in Python
How to use ChemSpider in Python
6 ways to string objects in Python
How to use PubChem in Python
Function synthesis and application in Python