Browse Source

checkdeadlinks: Move the main functionality into a separate function.

Emmanuel Gil Peyrot 2 years ago
parent
commit
8496245e85
1 changed files with 15 additions and 12 deletions
  1. 15
    12
      checkdeadlinks.py

+ 15
- 12
checkdeadlinks.py View File

@@ -70,28 +70,31 @@ def is_dead(url):
70 70
     else:
71 71
         return False
72 72
 
73
-def main():
74
-    parser = ArgumentParser(description=__doc__)
75
-    parser.add_argument('-v', '--verbose', action='store_true', help='Enables more verbosity')
76
-    parser.add_argument('-x', '--xep', type=int, help='Defines the number of the XEP to check')
77
-    args = parser.parse_args()
78
-
73
+def get_deadlinks(xep, is_verbose=False):
79 74
     global xepnum
80
-    xepnum = '%04d' % args.xep
75
+    xepnum = '%04d' % xep
81 76
 
82 77
     global verbose
83
-    verbose = args.verbose
78
+    verbose = is_verbose
84 79
 
85 80
     xepfile = 'xep-' + xepnum + '.xml'
86 81
     thexep = parse(xepfile)
87 82
 
88
-    if verbose:
89
-        print('Checking XEP-' + xepnum + ':')
90
-
91 83
     urls = [link.getAttribute("url") for link in thexep.getElementsByTagName("link")]
92 84
     urls += [image.getAttribute("src") for image in thexep.getElementsByTagName("img")]
93 85
 
94
-    deadlinks = [url for url in set(urls) if is_dead(url)]
86
+    if verbose:
87
+        print('Checking XEP-%s (%d links):' % (xepnum, len(urls)))
88
+
89
+    return [url for url in set(urls) if is_dead(url)]
90
+
91
+def main():
92
+    parser = ArgumentParser(description=__doc__)
93
+    parser.add_argument('-v', '--verbose', action='store_true', help='Enables more verbosity')
94
+    parser.add_argument('-x', '--xep', type=int, help='Defines the number of the XEP to check')
95
+    args = parser.parse_args()
96
+
97
+    deadlinks = get_deadlinks(args.xep, args.verbose)
95 98
 
96 99
     if deadlinks:
97 100
         for url in deadlinks:

Loading…
Cancel
Save