From fe463872ca9fd73a78af5664a529be9d19b28444 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 11 Jan 2024 11:41:42 +0100 Subject: [PATCH] searchengine autodetect --- src/install_searchengine_auto.py | 58 ++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/install_searchengine_auto.py diff --git a/src/install_searchengine_auto.py b/src/install_searchengine_auto.py new file mode 100644 index 0000000..c4a86bb --- /dev/null +++ b/src/install_searchengine_auto.py @@ -0,0 +1,58 @@ +import requests +from ping3 import ping + +def check_aara_websites(): + websites = [ + "https://search.spitfirebrowser.com/", + "https://araa.extravi.dev/", + "https://tailsx.com/" + ] + + results = [] + + for website in websites: + try: + # Measure loading time + response = requests.get(website, timeout=1) + loading_time = response.elapsed.total_seconds() + + # Measure ping + ping_result = ping(website.split("//")[1].split("/")[0], timeout=1) + + if ping_result is None: + # Set ping to 120ms if the website loads but doesn't respond to ping + ping_result = 0.12 + + results.append({ + 'website': website, + 'loading_time': loading_time, + 'ping': ping_result + }) + + # Print ping and loading time for each website + print(f"{website}: Ping = {ping_result} seconds, Loading Time = {loading_time} seconds") + + except requests.Timeout: + # Skip the website if it doesn't respond to ping within 2 seconds + print(f"{website}: Timeout, skipping...") + + except Exception as e: + # Handle other exceptions (e.g., website unreachable) + print(f"Error checking {website}: {e}") + + # Exclude websites that neither load nor respond to ping + results = [result for result in results if 'ping' in result] + + # Sort results based on loading time and ping (lower is better) + sorted_results = sorted(results, key=lambda x: (x['loading_time'], x['ping'])) + + # Return the best available website + best_website = sorted_results[0]['website'] if sorted_results else None + return best_website + +if __name__ == "__main__": + best_aara_website = check_aara_websites() + if best_aara_website: + print(f"\nThe best Aara website is: {best_aara_website}") + else: + print("\nNo suitable Aara website found.") \ No newline at end of file