Created
February 9, 2022 07:13
-
-
Save Abdur-rahmaanJ/7917dc5ab7f5d2aa37b2723909be08f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# using rich console | |
def ensure_internet(): | |
console = Console() | |
domains = [ | |
'https://google.com', | |
'https://yahoo.com', | |
'https://bing.com', | |
'https://www.ecosia.org', | |
'https://www.wikipedia.org' | |
] | |
results = [] | |
with console.status("Checking internet ...", spinner="dots"): | |
for domain in domains: | |
try: | |
requests.get(domain) | |
results.append(1) | |
except Exception as e: | |
results.append(0) | |
if not any(results): | |
print('No internet connection') | |
sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment