From 2df9c65eb05ee3c20ae9fe632519a81df3e7c319 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Tue, 23 Mar 2021 04:30:15 +0300 Subject: sms handling upd --- main.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 86dd972..604815f 100644 --- a/main.py +++ b/main.py @@ -12,15 +12,25 @@ trusted_phone = '' def sms_handler(sms: SMS, api: WebAPI): global trusted_phone - # print(f'from: {sms.phone}') - # print(f'text: {sms.text}') + print(f'from={sms.phone}, date={sms.date}, text={sms.text}') + + # just in case + phone = sms.phone + if phone.startswith('8') and len(phone) == 11: + phone = '+7' + phone[1:] + elif phone.startswith('7') and len(phone) == 11: + phone = '+' + phone + + if phone == trusted_phone: + print('this is a trusted phone, processing...') - if sms.phone == trusted_phone: text = sms.text.lower().strip() if text == 'you shall reboot!': + print('bye bye...') api.reboot() elif text == 'yo, get me some status': + print('gathering status') info = api.device_information() signal = api.device_signal() buf = [] @@ -38,9 +48,11 @@ def sms_handler(sms: SMS, api: WebAPI): api.send_sms(phone=trusted_phone, content=buf) elif text == 'switch it off': + print('switching it off') api.dataswitch(False) elif text == 'switch it on': + print('switching it on') api.dataswitch(True) -- cgit v1.2.3