예제 #1
0
def send_to(to, text):
    print("Sending SMS:\n%s" % text)

    d = datetime.datetime.now().strftime("%y-%m-%d_%H-%M-%S.%f")[:-3]
    p = os.path.join(SMS_DIR, d)
    if conf.KEY:
        alphabet = "ISO"
        f = Fernet(conf.KEY)
        encrypted = f.encrypt(text.encode("utf-8"))
        msg = "%8%" + encrypted.decode("utf-8")
    else:
        alphabet = "UCS-2"
        msg = text
    header = '\n'.join([f"To: {to}", f"Alphabet: {alphabet}", "", ""])
    print("Writing sms to %s" % p)
    with open(p, 'wb') as f:
        f.write(header.encode("UTF-8"))
        f.write(msg.encode("UTF-8"))
        f.flush()