Skip to content

Commit 0e47be6

Browse files
Copilotfelickz
andcommitted
Address code review feedback: simplify code and add dependency check
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
1 parent ca38881 commit 0e47be6

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

check_links.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,27 @@
22
"""
33
Link Checker for awesome-codeql repository
44
Checks all links in markdown files to ensure they are functional
5+
6+
Dependencies:
7+
- Python 3.6+
8+
- requests library (install with: pip install requests)
9+
10+
Usage:
11+
python3 check_links.py
512
"""
613

714
import re
815
import os
916
import sys
1017
import json
11-
import requests
18+
19+
try:
20+
import requests
21+
except ImportError:
22+
print("Error: 'requests' library is required.")
23+
print("Install it with: pip install requests")
24+
sys.exit(1)
25+
1226
from typing import List, Dict, Tuple
1327
from urllib.parse import urlparse
1428
from concurrent.futures import ThreadPoolExecutor, as_completed
@@ -105,8 +119,8 @@ def check_url(self, url: str) -> Dict:
105119
allow_redirects=True
106120
)
107121

108-
# Some servers don't support HEAD, try GET if HEAD fails
109-
if response.status_code in [405, 404]:
122+
# Some servers don't support HEAD, try GET if HEAD fails with 405
123+
if response.status_code == 405:
110124
response = self.session.get(
111125
url_without_fragment,
112126
timeout=TIMEOUT,
@@ -197,7 +211,7 @@ def main():
197211
md_files = []
198212
# Use the directory where the script is located as the repository root
199213
# This makes the script work from any location
200-
repo_root = os.path.dirname(os.path.abspath(__file__)) if os.path.dirname(os.path.abspath(__file__)) else os.getcwd()
214+
repo_root = os.path.dirname(os.path.abspath(__file__)) or os.getcwd()
201215

202216
for root, dirs, files in os.walk(repo_root):
203217
# Skip .git directory

0 commit comments

Comments
 (0)