Last active
November 21, 2020 08:15
-
-
Save Archeb/3e330a606b8a8bf64e11838cb6c5dadd to your computer and use it in GitHub Desktop.
SMS Forwarder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import serial | |
import re | |
import requests | |
ser = serial.Serial('/dev/ttyUSB0') | |
ser.write('AT+CSCS="UCS2"\n') | |
while 1: | |
read=ser.readline() | |
match=re.match(r'\+CMTI: "ME",(\d+)',read) | |
if(match): | |
ser.write('AT+CMGR=' + match.group(1) + '\n') | |
tmp=ser.readline() | |
info=ser.readline() | |
msg=ser.readline() | |
ser.write('AT+CMGD=' + match.group(1) + '\n') | |
infomatch=re.match(r'\+CMGR: "REC.*READ","(.*)",*"(.*)"',info) | |
if(infomatch): | |
srcphone=infomatch.group(1) | |
srctime=infomatch.group(2) | |
srcphone=unicode(srcphone.decode("hex"), "utf-16-be").encode("utf8") | |
msg=msg.strip('\r\n') | |
msg=unicode(msg.decode("hex"), "utf-16-be").encode("utf8") | |
finalmsg={'text':srcphone + ":" + msg + " [" + srctime + "]"} | |
mydata={'value1':srcphone,'value2':srctime,'value3':msg} | |
print mydata | |
requests.post('IFTTT API地址',json=mydata) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment