Skip to content

Instantly share code, notes, and snippets.

@fanyer
Forked from lihongjie0209/sms.py
Created October 4, 2018 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fanyer/ffb5ef25417f12af36b38f563f80e2e5 to your computer and use it in GitHub Desktop.
Save fanyer/ffb5ef25417f12af36b38f563f80e2e5 to your computer and use it in GitHub Desktop.
from androidhelper import Android
from time import sleep
import json
import urllib2
d = Android()
url = "youserver/sms/notify"
while(True):
messages = d.smsGetMessages(False)
for i in messages.result:
body = i["body"]
phone = i["address"]
# if not json, just pass
if (len(body)==0):
continue
# 简单判断是否为json
if body.strip()[0:1]=="{":
try:
request = urllib2.Request(url, body, headers={"from" : phone, "via_device":"python-app"})
f = urllib2.urlopen(request)
d.smsDeleteMessage(i["_id"])
print("send {0} to {1} with response {2}".format(body, url, f.read()))
except Exception, e:
print("send {0} to {1} fail: {0}".format(body, url, str(e)))
# print(i["_id"] + ":" + i["address"] + ":" + )
sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment