forked from KooriMoe/Gammu-Wechat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmsForward.py
54 lines (45 loc) · 1.7 KB
/
smsForward.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
import os
import sys
import requests
import json
import datetime
import subprocess
#微信推送程序
pushToWechatPyFile = '/home/ubuntu/Gammu-Wechat/pushToWechat.py'
if __name__ == "__main__":
#----------------------获取短信内容----------------------
numParts = int(os.environ['DECODED_PARTS'])
text = ''
#单条短信内容
if numParts == 0:
text = os.environ['SMS_1_TEXT']
#多条短信内容
else:
text = os.environ['DECODED_0_TEXT']
#发件人
sender = os.environ['SMS_1_NUMBER']
#发件日期和时间取当前系统时间
sendTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
# BEGIN SMSPROCESS.PY
# 短信来源识别
def getSource(content):
rule = r"【(.*?)】"
smsSource = ','.join(re.findall(rule, content))
return smsSource
# 菜鸟驿站提醒短信识别
if "【菜鸟驿站】" and "取件" in text:
pickupCode = ','.join(re.findall("\d{2}-\d{1}-\d{4}", text))
finalContent = "[菜鸟驿站:%s] "%pickupCode + text.replace("【菜鸟驿站】", "")
text = finalContent
# 验证码短信识别
if "验证码" in text:
captchaCode = ','.join(re.findall("\d{6}|\d{4}", text))
smsSource = getSource(text)
finalContent = "[%s:"%smsSource + "%s] "%captchaCode + text.replace("【%s】"%smsSource, "")
text = finalContent
# END SMSPROCESS.PY
#最终发送内容
sendContent = '发信人: ' + sender + '\n时间: ' + sendTime + '\n\n' + text
#--------------------转发到企业微信程序--------------------
subprocess.call(['/usr/bin/python3',pushToWechatPyFile,sendContent])