from com import Component, msgs
-import pexpect
-import time
+import commands
+
+
+_USSD_QUERY = "/usr/bin/ussdquery.py"
class USSDService(Component):
def __send_ussd(self, ussd_code):
-
- # thanks to KiberGus from talk.maemo.org for these lines
- child = pexpect.spawn("pnatd")
-
- child.send("AT\r")
- time.sleep(0.25)
- child.send('AT+CUSD=1,"%s",15\r' % ussd_code);
- time.sleep(0.25)
-
- child.readline()
- child.readline()
- child.readline()
-
- response = child.readline()
- child.sendeof()
- msg = self.__parse_response(response)
- return msg
-
-
- def __parse_response(self, s):
-
- idx1 = s.find("\"")
- idx2 = s.rfind("\"")
- text = s[idx1 + 1:idx2]
-
- return text
+ fail, msg = commands.getstatusoutput("%s '%s'" \
+ % (_USSD_QUERY, ussd_code))
+ if (fail):
+ return "ERROR: " + msg
+ else:
+ return msg
+
def handle_USSD_SVC_SEND(self, ussd_code):
- try:
- return self.__send_ussd(ussd_code)
- except:
- import traceback; traceback.print_exc()
- return "Error: cannot send USSD code"
+ return self.__send_ussd(ussd_code)