Check links on PRs and Update main build script

This commit is contained in:
Dave Machado 2017-12-28 23:44:24 -05:00
parent 2ceb3025ba
commit 21eb114d6d
No known key found for this signature in database
GPG key ID: 948D4778D01A7B3F
2 changed files with 58 additions and 54 deletions

View file

@ -1,32 +1,26 @@
#!/usr/bin/env python3
import httplib2
import json
import re
import socket
import sys
def parse_links(filename):
"""Returns a list of links from JSON object"""
data = json.load(open(filename))
links = []
for entry in data['entries']:
link = entry['Link']
https = True if link.startswith('https') else False
x = {
'link': link,
'https': https,
}
links.append(x)
"""Returns a list of URLs from text file"""
with open(filename) as fp:
data = fp.read()
raw_links = re.findall( \
'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', \
data)
links = [raw_link.replace(')', '') for raw_link in raw_links]
return links
def validate_links(links):
"""Checks each entry in JSON file for live link"""
print('Validating {} links...'.format(len(links)))
errors = []
for each in links:
link = each['link']
for link in links:
h = httplib2.Http(disable_ssl_certificate_validation=True, timeout=5)
try:
resp = h.request(link, 'HEAD')
@ -43,7 +37,7 @@ def validate_links(links):
if __name__ == "__main__":
num_args = len(sys.argv)
if num_args < 2:
print("No .json file passed")
print("No .md file passed")
sys.exit(1)
errors = validate_links(parse_links(sys.argv[1]))
if len(errors) > 0: