mirror of
https://github.com/moparisthebest/xeps
synced 2024-11-21 00:35:02 -05:00
checkdeadlinks: Move the main functionality into a separate function.
This commit is contained in:
parent
e626ca87aa
commit
8496245e85
@ -70,28 +70,31 @@ def is_dead(url):
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def get_deadlinks(xep, is_verbose=False):
|
||||||
|
global xepnum
|
||||||
|
xepnum = '%04d' % xep
|
||||||
|
|
||||||
|
global verbose
|
||||||
|
verbose = is_verbose
|
||||||
|
|
||||||
|
xepfile = 'xep-' + xepnum + '.xml'
|
||||||
|
thexep = parse(xepfile)
|
||||||
|
|
||||||
|
urls = [link.getAttribute("url") for link in thexep.getElementsByTagName("link")]
|
||||||
|
urls += [image.getAttribute("src") for image in thexep.getElementsByTagName("img")]
|
||||||
|
|
||||||
|
if verbose:
|
||||||
|
print('Checking XEP-%s (%d links):' % (xepnum, len(urls)))
|
||||||
|
|
||||||
|
return [url for url in set(urls) if is_dead(url)]
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = ArgumentParser(description=__doc__)
|
parser = ArgumentParser(description=__doc__)
|
||||||
parser.add_argument('-v', '--verbose', action='store_true', help='Enables more verbosity')
|
parser.add_argument('-v', '--verbose', action='store_true', help='Enables more verbosity')
|
||||||
parser.add_argument('-x', '--xep', type=int, help='Defines the number of the XEP to check')
|
parser.add_argument('-x', '--xep', type=int, help='Defines the number of the XEP to check')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
global xepnum
|
deadlinks = get_deadlinks(args.xep, args.verbose)
|
||||||
xepnum = '%04d' % args.xep
|
|
||||||
|
|
||||||
global verbose
|
|
||||||
verbose = args.verbose
|
|
||||||
|
|
||||||
xepfile = 'xep-' + xepnum + '.xml'
|
|
||||||
thexep = parse(xepfile)
|
|
||||||
|
|
||||||
if verbose:
|
|
||||||
print('Checking XEP-' + xepnum + ':')
|
|
||||||
|
|
||||||
urls = [link.getAttribute("url") for link in thexep.getElementsByTagName("link")]
|
|
||||||
urls += [image.getAttribute("src") for image in thexep.getElementsByTagName("img")]
|
|
||||||
|
|
||||||
deadlinks = [url for url in set(urls) if is_dead(url)]
|
|
||||||
|
|
||||||
if deadlinks:
|
if deadlinks:
|
||||||
for url in deadlinks:
|
for url in deadlinks:
|
||||||
|
Loading…
Reference in New Issue
Block a user