need an python script that uses skype4py to send an instant message

一笑奈何 提交于 2019-12-04 19:51:38

Should work based on the docs.

from Skype4Py import Skype
import sys

client = Skype()
client.Attach()
user = sys.argv[1]
message = ' '.join(sys.argv[2:]
client.SendMessage(user, message)

Usage:

$ python message.py someuser This is my message

You better not use this to spam people :D

If you need to do anything further with this, you better learn Python. For educational purposes, here's a line by line breakdown:

  1. Import class Skype from Skype4Py
  2. Import sys, which contains the arguments the script was passed from the command line in a list of strings, argv
  3. Create an instance of Skype, call it client
  4. Attach client to the user's Skype client
  5. Set the user to send it to to the second command line argument (first is the script name)
  6. Construct a string (the message) by joining each string in command line arguments after the 3rd (sys.argv[2:]), using a space as a separator
  7. Send the message to the user

4 Years later. I just want to mention that the arguments have probably changed in the latest versions of Skype. Meaning that the code below:

try:
    CmdLine = sys.argv[1]
except:
    print 'Missing command line parameter'
    sys.exit()

(which is a line from the Example Skype4Py script "callfriend.py" from github) will just give you the exception. I don't know what has changed, since 2 years ago I didn't use the Skype4Py but the argument sys.argv[1] isn't the send command anymore. Basically you ll get that sys.argv[1] is ouy of range. What you can do now is basically this:

import Skype4Py 
skype = Skype4Py.Skype()
skype.SendMessage('receiver's skypename','your message text')

And if you want to call a contact just use the code bellow.

skype.Placecall('skypename')

For new readers YMMV.. Microsoft have decided to get rid of the support for the Skype Desktop API.

https://blogs.skype.com/2013/11/06/feature-evolution-and-support-for-the-skype-desktop-api/

I'm not exactly sure what that means for skype4py.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!