Skip to content

Instantly share code, notes, and snippets.

@lihongjie0209
Created October 4, 2018 07:25
Show Gist options
  • Save lihongjie0209/a99516331c8b2d2ef057c39ade9b0a1d to your computer and use it in GitHub Desktop.
Save lihongjie0209/a99516331c8b2d2ef057c39ade9b0a1d 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