-
Notifications
You must be signed in to change notification settings - Fork 0
/
T4Wk4.py
171 lines (130 loc) · 3.75 KB
/
T4Wk4.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 23 14:24:14 2024
@author: marcus
"""
############
##
## Some preliminary chat
##
############
from time import time, ctime, gmtime
import os
import sys
import csv
## speedtest
##
import urllib.request
url = 'https://github.com/Mherstik/Automation_S2_2024/raw/refs/heads/main/20MB.zip'
# url = 'http://speed.hetzner.de/100MB.bin'
def checkSpeed(url):
'''
Parameters
----------
url : a GitHub URL
This will be a file on GitHub
Returns
-------
speed : float
the speed divided by the time it took to download.
'''
start_time = time() # or time.time()
#print(start_time)
## DO TESTS
with urllib.request.urlopen(url) as response:
response.read()
stop_time = time()
#print(stop_time)
downloadTime = stop_time - start_time
print(f'Elapsed time is {stop_time - start_time}')
speed = (20 * 8) / downloadTime
#print(f'Speed is {speed} from inside the checkSpeed')
return speed
speed = checkSpeed(url)
print(f'Download speed was {speed:.2f} Mbps')
# help(checkSpeed)
### OPTIONAL WITH SPEEDTEST-CLI module
###
import speedtest
servers = []
# If you want to test against a specific server
# servers = [1234]
threads = None
# If you want to use a single threaded test
# threads = 1
s = speedtest.Speedtest()
s.get_servers(servers)
s.get_best_server()
download_speed = s.download(threads=threads)
upload_speed = s.upload(threads=threads)
print(download_speed /1024/1024, upload_speed/1024/1024)
s.results.share()
results_dict = s.results.dict()
dl = results_dict.get('download')
print(dl/1024/1024)
# Check for modules
# if module not found
# - install module
# run hostname module
# check if PC has been seen
# if seen before
# - ask if they want to overwrite
# run modules
# put all info into file
# ----
# Tests
# Against new Windows PC
# Against new Windows PC without file
# Against new Windows PC without modules
# Against new Windows PC without internet
# Against new Windows PC without file and without modules
# Against new Windows PC without file and without modules without internet
# Against duplicate Windows PC
# Against duplicate Windows PC without file
# Against duplicate Windows PC without internet
#### Against duplicate Windows PC without modules
# Against duplicate Windows PC without file and without modules
# Against new Linux PC
# Against new Linux PC without file
# Against new Linux PC without internet
# Against new Linux PC without modules
# Against new Linux PC without file and without modules
# Against new Linux PC without file and without modules without internet
# Against duplicate Linux PC
# Against duplicate Linux PC without file
# Against duplicate Linux PC without internet
# Against duplicate Linux PC without modules
# Against duplicate Linux PC without file and without modules
# Against duplicate Linux PC without file and without modules without internet
# # Speedtest CLI
# import sys
# import subprocess
# import pkg_resources
# required = {'speedtest-cli', 'psutil', 'keyboard', 'pyautogui'}
# #required = {'psutil'}
# installed = {pkg.key for pkg in pkg_resources.working_set}
# print(required)
# print(installed)
# missing = required - installed
# if len(missing) > 0:
# print(f"{missing} is missing")
# # print(missing)
# if missing:
# python = sys.executable
# subprocess.check_call([python, '-m', 'pip', 'install', *missing], stdout=subprocess.DEVNULL)
# input()
# # Check for modules
# import psutil
# import speedtest
# #import pillow
# def speedTestModule():
# pass
# if module not found
# - install module
# run hostname module
# check if PC has been seen
# if seen before
# - ask if they want to overwrite
# run modules
# put all info into file