[Tutor] Please help disentangle my program logic

Mats Wichmann mats at wichmann.us
Sun Jan 5 13:18:11 EST 2020


On 1/5/20 9:00 AM, Robert Alexander wrote:
> Dear friends and tutors,
> Also thanks to some of your help I have written my first little python
> program.
> 
> It now lives on Github https://github.com/rjalexa/adsl-warn and its purpose
> is to monitor my home ADSL speeds, log them and if they degrade send me a
> Gmail email with increasing frequency.
> 
> While is does work ok, thinking about it’s overall flow there are things I
> do not like.
> 
> The next iteration should always log a line covering all cases from the LAN
> not functioning, to Internet not reachable (and of course in these cases I
> should log but not attempt to send an email), to the degraded (log + email)
> and normal (log only) speeds.

quick reaction: look into the logging module to control how, where and 
what to log. No need to reinvent the wheel.

> 
> I usually run this program as described in the requirements.txt file as
> "nohup python -u speedtest.py >> adsl.log &"

You shouldn't need to depend on shell syntax to get this stuff to 
work... the logging module will handle appending, or you can do it 
yourself (print can take a a file= argument to show where to send the 
output, and you open that file first in the appropriate mode)


More information about the Tutor mailing list