-
Notifications
You must be signed in to change notification settings - Fork 1
/
minimal_test.py
35 lines (30 loc) · 1021 Bytes
/
minimal_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import asyncio
import aiohttp
async def async_url_validation(session, url):
""" Validate the URL. """
async with session.get(
url) as response:
print(response)
return response.status
async def async_check_web(session, links):
""" Check all external links. """
results = await asyncio.gather(
*[async_url_validation(session, url) for url in links]
)
# That gets us a collection of the responses, matching up to each of
# the tasks, so loop through the links again and the index counter
# will point to the corresponding result.
i = 0
for link in links:
print(link, results[i])
i += 1
async def check_unique_links():
UNIQUE_LINKS = [
"https://twitter.com/linaroorg",
"https://www.linaro.org"
]
async with aiohttp.ClientSession() as session:
await async_check_web(session, UNIQUE_LINKS)
loop = asyncio.get_event_loop()
cul_result = loop.run_until_complete(check_unique_links())
loop.close()