Skip to content

Commit 5fb933b

Browse files
committed
Add broker link checker
1 parent 55a4150 commit 5fb933b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

check_links.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import urllib.request
2+
import re
3+
4+
5+
def load_file(path):
6+
with open(path, 'r') as file:
7+
data = file.read().replace('\n', '')
8+
return data
9+
10+
11+
if __name__ == '__main__':
12+
text = load_file('README.md')
13+
s = re.findall('\((.*?)\)',text)
14+
15+
broken_links = list()
16+
for link in s:
17+
try:
18+
conn = urllib.request.urlopen(link)
19+
except urllib.error.HTTPError as e:
20+
print('HTTPError: {}'.format(e.code) + ', ' + link)
21+
broken_links.append(link)
22+
except urllib.error.URLError as e:
23+
print('URLError: {}'.format(e.reason) + ', ' + link)
24+
except ValueError as e:
25+
print('ValueError: {}'.format(e) + ', ' + link)
26+
else:
27+
print('good' + ', ' + link)
28+
29+
with open('broken_links.txt', 'w') as f:
30+
for line in broken_links:
31+
f.write(f"{line}\n")

0 commit comments

Comments
 (0)