eternalegypt
eternalegypt copied to clipboard
Add SMS forwarder example
Love the library, thank you. I added an example of how one might make an SMS forwarder loop to retrieve messages sent to the SIM in the gateway and forward them to another device. Users could adapt it to forward messages to another messaging system if they prefer. I couldn't find any example showing usage of _sms_events and self.listeners, hope this serves as documentation for that. This code is published under the MIT license.
I used f-strings, if you want to support versions of python before 3.6 I can swap the f-string for .format.
Added a feature to allow the recipient of the forwarded SMSs to respond
e.g
sender sends: test
forwarded recipient receives: +xxsender: test
forwarded recipient responds: +xxsender: acknowledged
sender receives: acknowledged
Running this locally, I've been encountering the below error:
Traceback (most recent call last):
File "/home/alyssa/workspace/eternalegypt/eternalegypt/eternalegypt.py", line 289, in information
result = self._build_information(data)
File "/home/alyssa/workspace/eternalegypt/eternalegypt/eternalegypt.py", line 237, in _build_information
result.serial_number = data['general']['FSN']
KeyError: 'FSN'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/alyssa/workspace/eternalegypt/eternalegypt/eternalegypt.py", line 73, in wrapper
return await function(self, *args, **kwargs)
File "/home/alyssa/workspace/eternalegypt/eternalegypt/eternalegypt.py", line 293, in information
raise Error()
eternalegypt.eternalegypt.Error
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/alyssa/sms_forward.py", line 29, in wait_for_messages
await modem.information() # sends new sms objects to listener
File "/home/alyssa/workspace/eternalegypt/eternalegypt/eternalegypt.py", line 75, in wrapper
raise Error(str(function))
eternalegypt.eternalegypt.Error: <function LB2120.information at 0x7f5a4313e1f0>
It appears model.json might not always contain the requested data? information() might need to retry the request in the event that an error is raised. For now I've set up my loop to catch that error and retry from outside.
Thank you. I don't have time to look into this right now but will keep this open until I do.
Sorry for the delay, testing this now.
I do not get the traceback, is it frequent for you? Does it happen when idle or only when forwarding a message? I am using Netgear LB2120, do you have the same modem?
Never mind, I did get the error shortly after posting :-). I will look into that.
My findings so far: running with a 5 second interval and keep-alive seems to break the session eventually and reauthentication fails.
Setting the sleep time to 10 seconds seems to resolve this. It can also be avoided by creating the session like this:
connector = aiohttp.connector.TCPConnector(force_close=True)
websession = aiohttp.ClientSession(cookie_jar=jar, connector=connector)
The real fix would be to get the autologin to work properly but I am not yet sure how that is best done.