Created
December 19, 2018 09:57
-
-
Save srkama/d0548197fdb2d0547ca7ff649aaed94f to your computer and use it in GitHub Desktop.
async url checker with aiohttp
This file contains hidden or 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
import asyncio | |
import aiohttp | |
async def check_website(url_to_ping): | |
while True: | |
print("trying {0}".format(url_to_ping)) | |
try: | |
async with aiohttp.ClientSession() as session: | |
async with session.get(url_to_ping) as response: | |
response = await response.text() | |
await asyncio.sleep(10) | |
except Exception as e: | |
print(e) | |
await asyncio.sleep(10) | |
if __name__ == "__main__": | |
loop = asyncio.get_event_loop() | |
a = ["https://www.google.com", "https://www.ls.co.uk/"] | |
for url in a: | |
loop.create_task(check_website(url)) | |
loop.run_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment