Output details when running check-links.
@@ -16,12 +16,16 @@ class MatchTuple(NamedTuple):
def url_ok(match_tuple: MatchTuple) -> Tuple[MatchTuple, bool]:
try:
- return (match_tuple, requests.get(match_tuple.link).ok)
+ result = requests.get(match_tuple.link)
+ print(f" {result.status_code}: {match_tuple.source}")
+ return (match_tuple, result.ok)
except requests.ConnectionError:
return (match_tuple, False)
if __name__ == "__main__":
+ print("Finding all markdown files in the current directory...")
+
project_root = (pathlib.Path(__file__).parent / "..").resolve() # pylint: disable=no-member
markdown_files = project_root.glob('**/*.md')
@@ -34,15 +38,18 @@ if __name__ == "__main__":
for name, link in matches:
if 'localhost' not in link:
all_matches.add(MatchTuple(source=str(markdown_file), name=name, link=link))
+ print(f" {len(all_matches)} markdown files found")
+
+ print("Checking to make sure we can retrieve each web URL...")
with Pool(processes=10) as pool:
results = pool.map(url_ok, [match for match in list(all_matches)])
unreachable_results = [result for result in results if not result[1]]
if unreachable_results:
- print("UnReachable Links:")
+ print(f"Unreachable Links ({len(unreachable_results)}):")
for index, result in enumerate(unreachable_results):
- print("\n{}.".format(index))
+ print(" " + str(index))
print(" Source: " + result[0].source)
print(" Name: " + result[0].name)
print(" Link: " + result[0].link)
