Pergunta

i've installed skype4py. ( http://skype4py.sourceforge.net/doc/html/ )

i don't know python. i need a simple example script, that takes the first cmd argument as username and the second argument as message. this instant message should then be sent to the skype username.

does anyone know how to do this?

thanks a lot in advance

Foi útil?

Solução

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

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top