-
Notifications
You must be signed in to change notification settings - Fork 14
/
validation.py
34 lines (29 loc) · 1.03 KB
/
validation.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
#!/usr/bin/env python3
import re
import requests
print("Checking URL integrity...")
readme = open("README.md", "r")
lines = readme.readlines()
for line in lines:
# Anything that isn't a square closing bracket
name_regex = "[^]]+"
# http:// or https:// followed by anything but a closing paren
url_regex = "http[s]?://[^)]+"
markup_regex = '\[({0})]\(\s*({1})\s*\)'.format(name_regex, url_regex)
for match in re.findall(markup_regex, line):
length = len(match)
if length == 2:
source_name = match[0]
source_url = match[1]
try:
r = requests.get(source_url)
r.raise_for_status()
print ("✅ {}".format(source_name))
except Exception as e:
print ("❌ {} - {}".format(source_name, e))
elif length == 1:
source_name = match[0]
print ("❌ {} - Malformed markdown link.".format(source_name))
else:
print ("❌ {}".format(line))
print("Done.")