Skip to content

Instantly share code, notes, and snippets.

@Abdur-rahmaanJ
Created February 9, 2022 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Abdur-rahmaanJ/7917dc5ab7f5d2aa37b2723909be08f7 to your computer and use it in GitHub Desktop.
Save Abdur-rahmaanJ/7917dc5ab7f5d2aa37b2723909be08f7 to your computer and use it in GitHub Desktop.
# 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