-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspeed.py
73 lines (61 loc) · 2.22 KB
/
speed.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# pip install speedtest-cli
# Measures in bits per second
try:
import os
import time
import platform
from tqdm import tqdm
import speedtest as st
from typing import Union
from colorama import Fore, init
except ImportError as e_imp:
print(f"The following import error ocurred: {e_imp}")
init(autoreset=True)
def clear_screen() -> None:
actual_system = platform.system()
if actual_system == "Windows":
os.system("cls")
elif actual_system == "Linux":
os.system("clear")
else:
print("The script only runs in linux and windows os systems")
exit()
def print_results(data: dict[str, Union[str, int, float]]) -> None:
print("\n\n")
print(Fore.MAGENTA + "="*80)
print(Fore.GREEN + "INTERNET SPEED TEST RESULTS:".center(80))
print(Fore.MAGENTA + "="*80)
print(Fore.CYAN +
f"Download: {data['download']} | Upload:{data['upload']} | Ping: {data['ping']}".center(80))
print(Fore.MAGENTA + "-"*80)
print(Fore.CYAN +
f"HOST:{data['host']} | ISP:{data['isp']} | LATENCY: {data['latency']}".center(80))
print(Fore.MAGENTA + "-"*80)
def main_met() -> None:
data= {}
print(Fore.GREEN + "GETTING BEST AVAILABLE SERVERS, UPLOADING & DOWNLOADING SPEED.....")
speed= st.Speedtest()
speed.get_best_server()
for i in tqdm(range(100), colour="green", desc="Finding Optimal Server"):
time.sleep(0.005)
print("Processing data\n")
data["ping"] = speed.results.ping
downReal= speed.download(threads=None)
for _ in tqdm(range(100), colour="cyan", desc="Getting Download Speed"):
time.sleep(0.005)
print("Processing data\n")
upReal= speed.upload(threads=None, pre_allocate= False)
for i in tqdm(range(100), colour="red", desc="Getting Upload Speed"):
time.sleep(0.005)
# Conversion to real speed contracted
data["download"] = round(downReal / (10**6), 2)
data["upload"] = round(upReal / (10**6), 2)
# print(speed.results)
data["host"] = speed.results.server["host"]
data["isp"] = speed.results.client["isp"]
data["latency"] = speed.results.server["latency"]
del downReal, upReal
print_results(data)
if __name__== "__main__":
clear_screen()
main_met()