need an python script that uses skype4py to send an instant message
Asked Answered
D

3

1

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

Demand answered 27/12, 2010 at 1:12 Comment(3)
why don't you read the python tutorial and try to write one. Then if you have problems, you can ask specific questions and get specific answers. I bet you might even learn some python that way.Misprint
well, this was the last step i needed to make it work quickly. (zabbix skype notifications) i'm also planning to learn python :)Demand
Even better, learn to read docs... the accepted answer is barely copied from the docs github.com/Skype4Py/Skype4Py#sending-message.Lepage
T
10

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
Trend answered 27/12, 2010 at 1:24 Comment(2)
thanks a lot you've helped me so much. :) i will use this script so that zabbix can inform people about alerts via skype message. skype itself runs in xvfb on ubuntu server. i'm also writing a tutorial for this...Demand
I think Attach() is optional or not working as expected depending on Operating System. I don't use it and my script is working anyway. Seems deprecated or somethings like that, but i didn't see any kind of warning.Lepage
I
0

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.

Improve answered 25/8, 2016 at 2:56 Comment(0)
V
-1

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')
Vizor answered 18/10, 2014 at 11:12 Comment(3)
Are you saying that the code in the accepted answer wouldn't work any more? Or in what way is your post related to the question here?Recoup
2 year later. How to read if there is incoming call from whom?Bastille
sys.argv has NOTHING to do with Skype4Py, it is a basic Python module to pass arguments to the script. The accepted answer is totally OK and you have posted a SO wrong answer. Who let "userxxxxxx" to reply things? :-/Lepage

© 2022 - 2024 — McMap. All rights reserved.