-
Notifications
You must be signed in to change notification settings - Fork 17
/
linkcheck.py
executable file
·39 lines (34 loc) · 1.44 KB
/
linkcheck.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/python3
import sys
import os
import re
import requests
BASE_URL = "https://teamnewpipe.github.io/documentation"
RETURN_VALUE = 0
os.chdir("docs")
for filename in os.listdir():
#print(filename + ":")
if ".md" in filename:
with open(filename) as file:
filedata = file.read()
for link in re.findall('\[.*\]\(([^\)]*)\)', filedata):
if link.startswith("#"):
checkstring = "# " + link.replace("#", "").replace("-", " ")
if not checkstring in filedata.lower().replace("-", " "):
RETURN_VALUE = 1
print(filename + ": Could not find target for " + link)
else:
if link.startswith("img/"):
link = BASE_URL + "/" + link
if not link.startswith("http"):
RETURN_VALUE = 1
print(filename + ": " + link + " is not filled out or not http")
elif not link.startswith("https"):
RETURN_VALUE = 1
print(filename + ": " + link + " is not https")
else:
res = requests.get(link, timeout=5)
if res.status_code != 200:
RETURN_VALUE = 1
print(filename + ": " + link + " returns " + str(res.status_code))
sys.exit(RETURN_VALUE)