You are probably familiar with using chat bots to manage anything. For example, it is very convenient to run an assembly or layout by simply writing a message to one of your contacts in IM.
For Skype, there are various ready bots, one of the representatives -
Sevabot . They all use the Skype API, which Microsoft is going to kill, so the work of all these bots may soon become impossible. And I would not want this - in some places I use them to launch deployment.
How to be?
All living bots now work on the side of the desktop version of skype. I organize everything in the same way, but crawling to skype is not through the API.
')
For one-sided submission of a “go-ahead” to launch something, one can get away with the creaking only by extracting messages from Skype. Skype stores its messages inside the sqlite3 database in its data directory. I'll just sit in wait.
import sys import signal from time import sleep import sqlite3 if len(sys.argv) != 3: sys.stderr.write("Usage: %s <path to skype `main.db` file> <watch interval in seconds>\n" % sys.argv[0]) sys.exit(1) def int_handler(signum, frame): sys.exit(0) signal.signal(signal.SIGINT, int_handler) dbfilename = sys.argv[1] interval = float(sys.argv[2]) conn = sqlite3.connect(dbfilename) c = conn.cursor() c.execute("select id from Messages where id = (select max(id) from Messages);") (last_msg_id,) = c.fetchone() while True: sleep(interval) for id, body in c.execute("select id, body_xml from Messages where id > ?;", (last_msg_id,)): last_msg_id = max(id, last_msg_id) print body
Run:
./skype-watch.py ~/.Skype/skype_login/main.db 1
With stdout, the messages received and sent by the client run with some delay. By changing the request, you can add filtering by sender, changing the processing code - the reaction. The idea, I think, is understandable.
So what?
I would like to hear ideas on how to make it two-way. It only comes to mind that only “unsent” messages are put into the database, which Skype itself would send - after all, if the client failed to send and shut down, Skype remembers what needs to be sent.
Pros:
- No API needed.
- Just like an ax, few dependencies.
Minuses:
- Works only on reception.
- Does not use sqlite3 hooks.
Rep on githaba