Created
February 1, 2016 07:06
-
-
Save jcefoli/30454f372e7165434135 to your computer and use it in GitHub Desktop.
Parse speedtest-cli results
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| import os | |
| import sys | |
| # Simplified version of: http://www.engadget.com/2016/01/31/comcast-customer-complaint-bot/ aka http://pastebin.com/WMEh802V | |
| # Removed the Twitter integration and file system logging | |
| # To do: Add variables and math so the speeds are not hard coded and are based off a percent calculation | |
| def speedbot(): | |
| #Run speedtest-cli (pip install speedtest-cli, assumes it's in your system path) | |
| print ('Speed test in progress. This may take 30 seconds...') | |
| a = os.popen("speedtest-cli --simple").read() | |
| #Split the 3 line result (Ping, Download, Upload) | |
| lines = a.split('\n') | |
| #If there's some error... | |
| if "Cannot" in a: | |
| sys.exit("Internet is down or speedtest thingy didn't return expected output") | |
| #String parsing to get the values for ping, download, and upload | |
| else: | |
| pingResult = lines[0][6:11] | |
| downloadResult = lines[1][10:14] | |
| uploadResult = lines[2][8:12] | |
| #If less than 40, print something. If not, print something else. To do: less hard coding, more math and varibles | |
| if eval(downloadResult)<40: | |
| try: | |
| print ('Why is my internet speed ' + str(int(eval(downloadResult))) + 'down/' + str(int(eval(uploadResult))) + 'up when I pay for 50 MBPS down and 5 MBPS up?') | |
| except e: | |
| print (e) | |
| pass | |
| else: | |
| print ('Speed is good: ' + str(int(eval(downloadResult))) + ' MBPS down | ' + str(int(eval(uploadResult))) + ' MBPS up.') | |
| return | |
| if __name__ == '__main__': | |
| speedbot() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment