uses ussdquery.py now
authorpycage <martin.grimme@gmail.com>
Thu, 7 Jan 2010 18:09:40 +0000 (18:09 +0000)
committerpycage <martin.grimme@gmail.com>
Thu, 7 Jan 2010 18:09:40 +0000 (18:09 +0000)
git-svn-id: file:///svnroot/ussd-widget/trunk@12 d197f4d6-dc93-42ad-8354-0da1f58e353f

ussd-pad/src/opt/ussd-pad/components/ussd/USSDService.py

index bab9b4e..f4490a2 100644 (file)
@@ -1,7 +1,9 @@
 from com import Component, msgs
 
-import pexpect
-import time
+import commands
+
+
+_USSD_QUERY = "/usr/bin/ussdquery.py"
 
 
 class USSDService(Component):
@@ -12,40 +14,17 @@ 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)