View Single Post
Posts: 254 | Thanked: 122 times | Joined on Nov 2009
#20
This script is intended to be run from root. It prints current balance on russia MTS operator.
Code:
#/usr/bin/python

import pexpect
import time
from subprocess import *

child = pexpect.spawn('pnatd');
child.send('at\r');
time.sleep(0.25);
child.send('at+cusd=1,"*100#",15\r');
time.sleep(0.25);

child.readline();
child.readline();
child.readline();

reply = child.readline();
start = reply.find('"');
end = reply.find('"', start+1);
reply = reply[start+1:end];

child.sendeof();

p = Popen(['sh', 'ucsdecode.sh', reply], stdout=PIPE);
print p.communicate()[0];
The message is in UCS-2 encoding, so I need to convert it.
ucsdecode.sh
Code:
#/bin/sh
echo "$1" | echo -n -e $(tr -d '[:space:]' | sed 's/../\\x&/g') | iconv -f UCS-2BE -t UTF8
 

The Following 8 Users Say Thank You to KiberGus For This Useful Post: