Python library for converting plain text (ASCII) into GSM 7-bit character set?

前端 未结 4 756
梦如初夏
梦如初夏 2020-12-16 21:17

Is there a python library for encoding ascii data to 7-bit GSM character set (for sending SMS)?

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-16 21:20

    I could not find any library. But I think this should not need a library. Its somewhat easy to do.

    Here is Jon Skeet himself on the same topic.

    Example:

    s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    
    def ascii_to_gsm(ch):
        return bin(65 + s.index(ch))
    
    print ascii_to_gsm('A')
    print '--'
    
    binary_stream = ''.join([str(ascii_to_gsm(ch))[2:] for ch in s])
    print binary_stream
    

    You can also use dict to store mapping between ASCII and GSM 7-bit character set.

提交回复
热议问题