|
2 | 2 | """ |
3 | 3 | Link Checker for awesome-codeql repository |
4 | 4 | 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 |
5 | 12 | """ |
6 | 13 |
|
7 | 14 | import re |
8 | 15 | import os |
9 | 16 | import sys |
10 | 17 | 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 | + |
12 | 26 | from typing import List, Dict, Tuple |
13 | 27 | from urllib.parse import urlparse |
14 | 28 | from concurrent.futures import ThreadPoolExecutor, as_completed |
@@ -105,8 +119,8 @@ def check_url(self, url: str) -> Dict: |
105 | 119 | allow_redirects=True |
106 | 120 | ) |
107 | 121 |
|
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: |
110 | 124 | response = self.session.get( |
111 | 125 | url_without_fragment, |
112 | 126 | timeout=TIMEOUT, |
@@ -197,7 +211,7 @@ def main(): |
197 | 211 | md_files = [] |
198 | 212 | # Use the directory where the script is located as the repository root |
199 | 213 | # 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() |
201 | 215 |
|
202 | 216 | for root, dirs, files in os.walk(repo_root): |
203 | 217 | # Skip .git directory |
|
0 commit comments