diff --git a/.gitignore b/.gitignore
index b6e4761..4b92b40 100644
--- a/.gitignore
+++ b/.gitignore
@@ -127,3 +127,6 @@ dmypy.json
# Pyre type checker
.pyre/
+
+# .idea folder of Jetbrains IDEs
+.idea/
\ No newline at end of file
diff --git a/LEARN.md b/LEARN.md
index f64361a..68aabf4 100644
--- a/LEARN.md
+++ b/LEARN.md
@@ -14,6 +14,8 @@ dependent files, displaying brand name & version
**system_info.py** fetches system info such as Fedora version & architecture by
running the command `hostnamectl` with `grep` and gives the data back to **index.py**
+- If the system is not Fedora, it will autoselect Fedora 36
+ - If the system is Fedora but version not specified, it will fetch the version from `hostnamectl` command
**scrape.py** used for scraping mirror list from Fedora mirror manager using `beautifulsoup4`. After fetching system info **index.py** calls this file
1. From Fedora version & architecture it fetches HTML of mirror manager e.g. `https://admin.fedoraproject.org/mirrormanager/mirrors/Fedora/38/x86_64`
diff --git a/README.md b/README.md
index c6e99db..74fffc8 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@
A Python script to measure Fedora mirror speed
- version: 2.1.0
+ version: 2.2.0
@@ -37,6 +37,14 @@ After using MiMe I get around **2 Mbps!**
## Changelog
---
+### 2.2.0:
+- Fixed: download if file is not present
+- Added: shows best mirror
+- Autoselect Fedora 36 if run on distro other than Fedora
+
+**Known Issues**
+- Flags not rendering `speedtest.py:13:5`
+
### 2.1.0:
- Added support for Pre-Release
- Speedtest all the servers without typing **all**
diff --git a/index.py b/index.py
index 0c8ddd3..be9491a 100644
--- a/index.py
+++ b/index.py
@@ -5,7 +5,7 @@
import speedtest
name = "Fedora MiMe"
-version = '2.1.0'
+version = '2.2.0'
os.system('clear')
print(f"{name}")
diff --git a/speedtest.py b/speedtest.py
index 05e67bc..cf8667b 100644
--- a/speedtest.py
+++ b/speedtest.py
@@ -14,7 +14,7 @@ def code_to_country(code):
# Checking if Fedora version is pre-release or stable
-def ping(ostm, archi):
+def check_release(ostm, archi):
template = f"{ostm}/Everything/{archi}/os/images/efiboot.img"
pre_release_url = f'https://ap.edge.kernel.org/fedora/development/{template}'
@@ -25,13 +25,17 @@ def ping(ostm, archi):
return 'releases'
+best_server = {'link': '', 'speed': 0.0}
+
+
def speed_test(links, ostm, archi):
- version = ping(ostm, archi)
+ version = check_release(ostm, archi)
while True:
os.system('clear')
country_code = list(links.keys())
for i in range(len(country_code)):
- print(f"{i + 1}: {code_to_country(country_code[i])}({len(links[country_code[i]])} {'mirrors' if len(links[country_code[i]]) > 1 else 'mirror'})")
+ print(
+ f"{i + 1}: {code_to_country(country_code[i])}({len(links[country_code[i]])} {'mirrors' if len(links[country_code[i]]) > 1 else 'mirror'})")
print("Leave blank: to test all mirrors")
country_code_number = input("\nEnter number separated by comma(enter q to quit): ")
@@ -49,7 +53,8 @@ def speed_test(links, ostm, archi):
print('\nStarting speedtest...\n')
for ccn in country_code_number:
- print(f"\nChecking {code_to_country(country_code[int(ccn) - 1])} mirrors: {links[country_code[int(ccn) - 1]]}\n")
+ print(
+ f"\nChecking {code_to_country(country_code[int(ccn) - 1])} mirrors: {links[country_code[int(ccn) - 1]]}\n")
filtered_links = links[country_code[int(ccn) - 1]]
for link in filtered_links:
url = f"{link}/{version}/{ostm}/Everything/{archi}/os/images/efiboot.img"
@@ -57,6 +62,16 @@ def speed_test(links, ostm, archi):
with io.BytesIO() as f:
start = time.perf_counter() # starting time
r = requests.get(url, stream=True) # making requestL
+
+ # checking if file is in place
+ if r.status_code != 200:
+ if link.endswith('/linux'):
+ print(f"Skipping {link} \nReason: file not found\nError code: {r.status_code}\n")
+ continue
+ filtered_links.append(f"{link}/linux")
+ print(f"Skipping {link} \nReason: File might not be in place\nAdding into queue\n")
+ continue
+
total_length = r.headers.get('content-length') # file size
dl = 0
if total_length is None: # no content length header
@@ -69,8 +84,10 @@ def speed_test(links, ostm, archi):
sys.stdout.write(
f"\r{link} [%s%s] %s Kbps" % (
'=' * done, ' ' * (30 - done), dl // (time.perf_counter() - start) / 1000))
-
- speed = dl // (time.perf_counter() - start) / 100000
print('\n')
- if speed == 0.0:
- filtered_links.append(f"{link}/linux")
+ speed = dl // (time.perf_counter() - start) / 1000
+ if speed > best_server['speed']:
+ best_server['speed'] = speed
+ best_server['link'] = link
+
+ print(f"Fastest mirror: {best_server['link']}\nSpeed: {best_server['speed']}")
diff --git a/system_info.py b/system_info.py
index d22d878..9e67108 100644
--- a/system_info.py
+++ b/system_info.py
@@ -34,8 +34,8 @@ def architecture():
def os():
operating_system = hostnamectl('Operating System')
- if re.search(r"^Fedora [1-9]+", operating_system):
- print("Fedora Linux not found")
- return None
+ if not re.search(r"^Fedora [1-9]+", operating_system): # if ran on non-fedora distro
+ print("Fedora Linux not found\nAutoselecting Fedora 36\n")
+ return 36
result = re.findall("\d+", operating_system)[0]
return int(result) # result = 36 // int