Qpython安卓手机读取短信

  • Post author:
  • Post category:python


红米 Redmi Note 9 Pro

MIUI 12.5.2

Android 11

权限开启



读取一个号码的所有信息保存为xlsx

from androidhelper import Android
from openpyxl import load_workbook
from openpyxl import Workbook
import time


d = Android()
sms_data = d.smsGetMessages(False, "inbox")

iflytek = [sms for sms in sms_data.result if sms['address'] == '号码']
iflytek.reverse()
   
"""
address就是对方手机号
date就是短信息的时间戳
body是短信具体内容
read表示已读未读,1为已读,估计0是未读。
"""

wb = Workbook()
sheet = wb.active
def do_xlsx(time_stamp, body):
    timeArray = time.localtime(int(time_stamp))
    day = time.strftime("%m.%d", timeArray)
    dayTime = time.strftime("%H:%M:%S", timeArray)
    sheet.append([day, dayTime, body])
    print("写入", [day, dayTime, body])


for i in iflytek:
    body = i['body']
    timestamp = i['date'][:-3]
    do_xlsx(timestamp, body)    


wb.save("20210610.xlsx")



版权声明:本文为qq_44810930原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。