[Tutor] Please help disentangle my program logic

Robert Alexander gogonegro at gmail.com
Sun Jan 5 11:00:54 EST 2020


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.

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

As you can see in the current version the st_json function spits out two
log lines which have a different format from the usual ones and quits
altogether breaking the while True loop. This might be acceptable in the
“Speedtest prerequisite not installed” case but not for the “Internet down
case” which should be logged (the frequencies of logging are computed in
the set_frequency function and currently do not contemplate the
Internet-offline case).

So currently the function calls in the main are a bit of spaghetti logic
which makes it hard to define a standard modular log line that could be
parseable in the future.

Two main questions are:

A) Are there tools to quickly/neatly look at a flow of your program? For
example how would you modify the st_json function to handle both a
successful measure but also the other two cases (Internet not reachable and
speediest CLI not installed)?

B) Suggestions to make this little program more rational?

Thank you all very much in advance
Robert


More information about the Tutor mailing list