DEV Community

Discussion on: A free utility for easy routing in USSD applications

Collapse
 
tawn33y profile image
Tony • Edited

Hi! Not directly. You will need to rewrite the code from Typescript to Python. The good news is that it's just 35 lines of code.

Here's the source: github.com/tawn33y/ussd-router/blo...

Let me know if you face any issues.
Cheers!

Collapse
 
ditsarl profile image
ditsarl

Hi ! Thanks a lot. I have encoded the lines below and it's work perfectly :

coding: utf-8

def goBack(str, keyword='00'):

strArray = str.split('*')
newStrArray = []

for i in range(len(strArray)):

if strArray[i] == keyword:
    newStrArray = newStrArray[slice(0, -1)]
else:
    newStrArray.append(strArray[i])
Enter fullscreen mode Exit fullscreen mode

return "*".join(newStrArray)

def goToHome(str, keyword='0'):

strArray = str.split('*')
newStr = str

for i in reversed(range(len(strArray))):
if strArray[i] == keyword:
newStr = "*".join(strArray[i+1:])
break

return newStr

def ussdRouter(str, goToHomeKeyword='0', goBackKeyword='00'):
return goBack(goToHome(str, goToHomeKeyword), goBackKeyword)

Thread Thread
 
tawn33y profile image
Tony

This is great!! 🙌🏽

Thanks for sharing! When you get a minute, feel free to create a python package for the same, and I can add a hyperlink pointer to this in the js package for future people who would like a python version

Thread Thread
 
ditsarl profile image
ditsarl
Thread Thread
 
tawn33y profile image
Tony

Awesome! 🙌🏽