Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,31 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
import speedtest
|
| 3 |
-
import time
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
try:
|
| 11 |
-
stt = speedtest.Speedtest()
|
| 12 |
-
stt.get_best_server()
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
upload = stt.upload()
|
| 17 |
-
end = time.time()
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import speedtest
|
|
|
|
| 2 |
|
| 3 |
+
def test_internet_speed():
|
| 4 |
+
"""
|
| 5 |
+
Tests the internet download and upload speed using speedtest-cli.
|
| 6 |
+
"""
|
| 7 |
+
try:
|
| 8 |
+
st = speedtest.Speedtest()
|
| 9 |
+
print("Testing internet speed...")
|
| 10 |
|
| 11 |
+
# Perform the download speed test
|
| 12 |
+
download_speed = st.download() / 1_000_000 # Convert to Mbps
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
# Perform the upload speed test
|
| 15 |
+
upload_speed = st.upload() / 1_000_000 # Convert to Mbps
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
# Get ping
|
| 18 |
+
servernames = []
|
| 19 |
+
st.get_servers(servernames)
|
| 20 |
+
ping = st.results.ping
|
| 21 |
|
| 22 |
+
# Print the results
|
| 23 |
+
print(f"Download Speed: {download_speed:.2f} Mbps")
|
| 24 |
+
print(f"Upload Speed: {upload_speed:.2f} Mbps")
|
| 25 |
+
print(f"Ping: {ping:.2f} ms")
|
| 26 |
|
| 27 |
+
except speedtest.SpeedtestException as e:
|
| 28 |
+
print(f"An error occurred during the speed test: {e}")
|
| 29 |
+
|
| 30 |
+
if __name__ == "__main__":
|
| 31 |
+
test_internet_speed()
|