From: Jordi Riera Date: Sat, 31 May 2014 11:09:28 +0000 (+0200) Subject: scripts to test ofind dead links in urls provided in binding docstrings. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=323a1367ea7d96bc40aa14d4c40ae683019b4ed5;p=tweepy.git scripts to test ofind dead links in urls provided in binding docstrings. --- diff --git a/bindings_url_parser.py b/bindings_url_parser.py new file mode 100644 index 0000000..252fbb7 --- /dev/null +++ b/bindings_url_parser.py @@ -0,0 +1,33 @@ +""" script to parse the url of bindings and find if the page exists or not """ +import pprint +import re +import os +import requests + +__author__ = 'jordiriera' + +url_root = 'https://dev.twitter.com' +reference_line = re.compile(':reference: ({}.*) "'.format(url_root)) + + +def parse(filename): + dead_links = [] + with open(filename, 'r') as file_: + for line in file_.readlines(): + res = reference_line.search(line) + if res: + if not exists(res.group(1)): + dead_links.append(res.group(1)) + + return dead_links + + +def exists(path): + r = requests.head(path) + return r.status_code == requests.codes.ok + + +if __name__ == '__main__': + root = os.path.dirname(os.path.abspath(__file__)) + filename = os.path.join(root, 'tweepy', 'api.py') + pprint.pprint(parse(filename))