| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
# SPDX-License-Identifier: Apache-2.0 |
| 4 |
# Copyright 2025 The Meson development team |
| 5 |
|
| 6 |
import sys |
| 7 |
import re |
| 8 |
import aiohttp |
| 9 |
import asyncio |
| 10 |
|
| 11 |
LINK = re.compile(r'\[(?P<name>[A-Za-z0-9 ]+)\]\((?P<url>.*?)\)') |
| 12 |
|
| 13 |
|
| 14 |
async def fetch(session, name, url, timeout): |
| 15 |
try: |
| 16 |
async with session.get(url, timeout=timeout) as r: |
| 17 |
if not r.ok: |
| 18 |
return (name, url, r.status) |
| 19 |
except Exception as e: |
| 20 |
return (name, url, str(e)) |
| 21 |
|
| 22 |
|
| 23 |
async def main(filename): |
| 24 |
with open(filename) as f: |
| 25 |
text = f.read() |
| 26 |
timeout = aiohttp.ClientTimeout(total=60) |
| 27 |
async with aiohttp.ClientSession() as session: |
| 28 |
tasks = [] |
| 29 |
for link in LINK.finditer(text): |
| 30 |
name, url = link.groups() |
| 31 |
task = asyncio.ensure_future(fetch(session, name, url, timeout)) |
| 32 |
tasks.append(task) |
| 33 |
responses = asyncio.gather(*tasks) |
| 34 |
errors = [r for r in await responses if r is not None] |
| 35 |
for name, url, result in errors: |
| 36 |
print(f'"{name}" {url} {result}') |
| 37 |
if errors: |
| 38 |
sys.exit(1) |
| 39 |
|
| 40 |
|
| 41 |
if __name__ == '__main__': |
| 42 |
asyncio.run(main(sys.argv[1])) |