Skip to content

Instantly share code, notes, and snippets.

@flavioVitoriano
Last active February 21, 2019 15:25
Show Gist options
  • Save flavioVitoriano/4cdc2ac4224b29e173de3b3a4aa2c5fd to your computer and use it in GitHub Desktop.
Save flavioVitoriano/4cdc2ac4224b29e173de3b3a4aa2c5fd to your computer and use it in GitHub Desktop.
class Sms:
def __init__(self, msg):
self.mapeador = {'1': "",'2': "abc",'3': "def",'4': "ghi",'5': "jkl",'6': "mno",'7': "pqrs",'8': "tuv",'9': "wxyz",'0': " ",' ': "pause"}
self.mensagem = msg
def parseData(self):
result = []
lista = ""
temp_char = None
for char in self.mensagem:
if char == '1':
continue
if temp_char != char:
if lista:
result.append(lista)
lista = ""
lista += char
temp_char = char
result.append(lista)
return result
def dataToText(self, data):
decode = ""
for digitos in data:
if digitos == " ":
decode += ""
else:
num = digitos[0]
indice = len(digitos)-1
decode = decode + self.mapeador[num][indice]
return decode
def Texto(self):
dados = self.parseData()
resultado = self.dataToText(dados)
print(resultado)
try:
dados = sys.argv[1]
except IndexError:
print("Erro, coloque a mensagem no argumento!")
exit()
msg = Sms(dados)
print(msg.parseData())
msg.Texto()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment