-
Notifications
You must be signed in to change notification settings - Fork 1
/
reflections.txt
33 lines (26 loc) · 2.45 KB
/
reflections.txt
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
The idea came about because my ISP is garbage, and I wanted to see if there is a discernable pattern
of downtime.
I started by going to speedtest.net by Ookla to see if they had an API which would allow me to test
my internet speed in a script. They did not. However, they had a nifty CLI! So I downloaded that.
From there, I learned how to write the results of the speed test CLI to a file directly from the
command line.
Then, I used python's subprocess library to execute the speed test command at regular intervals.
I discovered that there was actually a python module I could download that tests internet speed, which eliminated the need to use
subprocess!
However, those intervals were not as regular as I would have liked. I was using time.sleep() functions
which unfortunately weren't precise enough because it had to factor in the time taken up by the actual
speed test!
So, I added a list of times - quarters of the hour, to be precise - to constantly compare the current time. If it matches,
then it runs the test. In the future, I'd like to add options for the user to adjust their increments instead of having it
*gasp* hard-coded! To do this, I had to learn more about the datetime module and how to deal with datetime objects. There
was also an element of slicing in order to match times.
This application can now run (at least on my computer) with pythonw (or pyw) which will allow it to run completely in the background.
To do this, all output had to be routed to files instead of the console, since pythonw does not seem to work when there's console
output. Story time: this took some time to research since it was unclear how to stop the program once it started running. All sources
indicated that a peek inside task manager will show pyw.exe running, and you can just end the task there. However, I kept being
unable to see it in my own task manager. It turned out that the culprit wasn't only those pesky print functions, but having a path
to output any errors! Remember, pyw doesn't like command line output. I found a solution which allowed for errors to be output to a
file from the command line. From this point, I was able to get the program to run in the background, along with a visible process
to easily terminate. My last step was learning how to view all running processes and terminate processes all from the command line.
Super easy. I incorporated everything into two batch files, one to run the script, and one to kill it. It's been working without
a hitch!