Skip to content

Commit e3dc420

Browse files
committed
Use uv for link checking script
Use uv's inline script dependencies to make uv the only requirement: https://docs.astral.sh/uv/guides/scripts/#declaring-script-dependencies Run with: uv run checklinks.py README.md
1 parent 21c1309 commit e3dc420

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

checklinks.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#!/usr/bin/env python3
2-
3-
# pipenv --three
4-
# pipenv install requests mistletoe
5-
# pipenv run ./checklinks.py README.md
1+
# /// script
2+
# dependencies = [
3+
# "requests==2.32.3",
4+
# "mistletoe==1.4.0",
5+
# ]
6+
# ///
67

78
import sys
89
from mistletoe import Document, span_token, ast_renderer
@@ -14,7 +15,7 @@
1415
FAILURE_EMOJI = unicodedata.lookup('Cross Mark')
1516

1617
if len(sys.argv) != 2:
17-
print('Usage: pipenv run ./checklinks.py README.md')
18+
print('Usage: uv run checklinks.py README.md')
1819
sys.exit(1)
1920

2021
urls = []
@@ -40,7 +41,10 @@ def walk(token):
4041
session.headers.update({'User-Agent': USER_AGENT})
4142
for url in urls:
4243
try:
43-
r = session.get(url)
44+
r = session.get(url, timeout=10)
45+
except requests.exceptions.ReadTimeout:
46+
print(f'{FAILURE_EMOJI} {url} connection timeout')
47+
continue
4448
except requests.exceptions.ConnectionError:
4549
print(f'{FAILURE_EMOJI} {url} connection error')
4650
continue

0 commit comments

Comments
 (0)