File: bindings_url_parser.py

package info (click to toggle)
tweepy 3.6.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,776 kB
  • sloc: python: 3,239; makefile: 89
file content (33 lines) | stat: -rw-r--r-- 836 bytes parent folder | download | duplicates (3)
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
""" 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))