Is there a python library for encoding ascii data to 7-bit GSM character set (for sending SMS)?
I faced a similar issue recently where we were getting gsm7bit decoded text messages, mostly for Verizon carrier with Spanish characters, from the aggregator and we were not able to decode it successfully. Here is the one I created with the help of other answers in the forum. This is for Python 2.7.x.
def gsm7bitdecode(text):
gsm = (u"@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\x1bÆæßÉ !\"#¤%&'()*+,-./0123456789:;<=>"
u"?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑÜ`¿abcdefghijklmnopqrstuvwxyzäöñüà")
ext = (u"````````````````````^```````````````````{}`````\\````````````[~]`"
u"|````````````````````````````````````€``````````````````````````")
text = ''.join(["{0:08b}".format(int(text[i:i+2], 16)) for i in range(0, len(text), 2)][::-1])
text = [(int(text[::-1][i:i+7][::-1], 2)) for i in range(0, len(text), 7)]
text = text[:len(text)-1] if text[-1] == 0 else text
text =iter(text)
result = []
for i in text:
if i == 27:
i = next(text)
result.append(ext[i])
else:
result.append(gsm[i])
return "".join(result).rstrip()