-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgammu2wx.py
75 lines (64 loc) · 2.46 KB
/
gammu2wx.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
# encoding: utf-8
import time
from datetime import datetime
from typing import Mapping
import requests
import os
import sys
from config import WX_REPORT_URL, TG_REPORT_URL
def send_mqtt(content):
pass
def send_telegram(content):
data = {'text': content}
proxies = {
'http': 'http://127.0.0.1:2081',
'https': 'http://127.0.0.1:2081',
}
try:
r = requests.post(TG_REPORT_URL, data=data, proxies=proxies)
print('send tg ok:', r.status_code, r.text)
except Exception as e:
print('send tg failed: {}'.format(e))
def send_message(title, desp):
data = {'title': title, "desp": desp}
try:
r = requests.get(WX_REPORT_URL, data=data)
print('send wx ok:', r.status_code, r.text)
except Exception as e:
print('send wx failed: {}'.format(e))
def gammu_forward():
print('SMS_MESSAGES:{}'.format(os.getenv('SMS_MESSAGES')))
print('DECODED_PARTS:{}'.format(os.getenv('DECODED_PARTS')))
# print('PHONE_ID:{}'.format(os.getenv('PHONE_ID')))
# print('SMS_1_NUMBER:{}'.format(os.getenv('SMS_1_NUMBER')))
# print('SMS_1_TEXT:{}'.format(os.getenv('SMS_1_TEXT')))
# print('SMS_2_NUMBER:{}'.format(os.getenv('SMS_2_NUMBER')))
# print('SMS_2_TEXT:{}'.format(os.getenv('SMS_2_TEXT')))
# print('DECODED_1_TEXT:{}'.format(os.getenv('DECODED_1_TEXT')))
# print('DECODED_1_MMS_SENDER:{}'.format(os.getenv('DECODED_1_MMS_SENDER')))
# print('DECODED_2_TEXT:{}'.format(os.getenv('DECODED_2_TEXT')))
# print('DECODED_2_MMS_SENDER:{}'.format(os.getenv('DECODED_2_MMS_SENDER')))
now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
sender = os.environ['SMS_1_NUMBER']
numParts = int(os.environ['DECODED_PARTS'])
text = ""
try:
if numParts == 0:
text = os.environ['SMS_1_TEXT']
else:
for i in range(1, numParts + 1):
envName = "DECODED_%d_TEXT" % i
if envName in os.environ:
text = text + os.environ[envName]
except Exception as e:
print("forward {} sms error {}", sender, e)
title = "来自 {} 的短信".format(sender)
desp = "\n{} ({})".format(text, now)
# desp = "\n内容:{}\n来自:{}\n时间:{}".format(text, sender, now)
print('forward sms for [{}]'.format(sender))
send_message(title, desp)
send_telegram("{}\n{}".format(title, desp))
if __name__ == '__main__':
gammu_forward()
# send_telegram(sys.argv[1])