read/del one sms
This commit is contained in:
parent
f7b32ec3f2
commit
f592d01220
@ -21,6 +21,7 @@ parser_send.add_argument('-m', '--message', help='message contents', metavar='ME
|
||||
|
||||
parser_read = subparsers.add_parser('read', help='read text messages')
|
||||
parser_read.add_argument('-i', '--interface', help='serial interface', metavar='TTY', required=True)
|
||||
parser_read.add_argument('-n', '--number', help='sms number', metavar='TTY', required=True)
|
||||
|
||||
|
||||
|
||||
@ -56,13 +57,40 @@ def readMessage(phone):
|
||||
finally:
|
||||
phone.close()
|
||||
|
||||
|
||||
def readOne(phone):
|
||||
try:
|
||||
time.sleep(0.5)
|
||||
phone.write(b'AT+CMGL=1\r')
|
||||
read = phone.readlines()
|
||||
badChars = ['OK', 'AT']
|
||||
for msg in read:
|
||||
if not any(x in str(msg) for x in badChars):
|
||||
print(str(msg.decode("utf-8")))
|
||||
time.sleep(0.5)
|
||||
finally:
|
||||
phone.close()
|
||||
|
||||
def delOne(phone):
|
||||
try:
|
||||
time.sleep(0.5)
|
||||
phone.write(b'AT+CMGD=1\r')
|
||||
read = phone.readlines()
|
||||
badChars = ['OK', 'AT']
|
||||
for msg in read:
|
||||
if not any(x in str(msg) for x in badChars):
|
||||
print(str(msg.decode("utf-8")))
|
||||
time.sleep(0.5)
|
||||
finally:
|
||||
phone.close()
|
||||
|
||||
def main():
|
||||
phone = serial.Serial(args.interface, 115200, timeout=5)
|
||||
if sys.argv[1] == 'send':
|
||||
sendText(phone, args.recipient, args.message)
|
||||
elif sys.argv[1] == 'read':
|
||||
readMessage(phone)
|
||||
elif sys.argv[1] == 'one':
|
||||
readOne(phone)
|
||||
else:
|
||||
parser.print_help()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user