2 # -*- coding: utf-8 -*-
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published
5 ## by the Free Software Foundation; version 2 and higer.
7 ## Guseynov Alexey (kibergus bark-bark gmail.com) 2010
11 from subprocess import *
15 if len(sys.argv) != 2:
16 print "Usage: ussdquery.py <ussd number>"
19 # Operations should timeout in 30 seconds.
20 # I'm not shure, that readline uses timeouts
21 child = pexpect.spawn('pnatd', [], 30);
23 # Read our "at" command
28 child.send('at+cusd=1,"'+(sys.argv[1])+'",15\r');
29 # Read our query echoed back
33 replystring = child.readline();
34 start = replystring.find('"');
35 end = replystring.find('"', start+1);
36 reply = replystring[start+1:end];
37 encoding = replystring[end+2:].strip();
42 reply = gsmdecode.decode(reply, int(encoding))