File: check_urls.py

package info (click to toggle)
fiona 1.10.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,632 kB
  • sloc: python: 12,616; makefile: 214; sh: 45
file content (35 lines) | stat: -rw-r--r-- 999 bytes parent folder | download | duplicates (2)
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
34
35
import requests
import glob
import re


def test_urls(files):
    headers = {'User-Agent': 'Mozilla/5.0 (compatible; MSIE 6.0; Fiona CI check)'}

    for fpath in files:
        print(f"Processing: {fpath}")
        with open(fpath) as f:

            text = f.read()
            urls = re.findall('(https?:\\/\\/[^\\s`>\'"()]+)', text)

            for url in urls:
                http_code = None
                try:
                    r = requests.get(url, headers=headers)
                    http_code = r.status_code
                    warn = ''
                    if not http_code == 200:
                        warn = ' <--- !!!'
                except Exception as e:
                    warn = str(e)

                if len(warn) > 0:
                    print(f"\t {url} HTTP code: {http_code} {warn}")


print("Test URLs in documentation")
test_urls(glob.glob('**/*.rst', recursive=True))
print('')
print('Test URLs in code')
test_urls(glob.glob('fiona/**/*.py', recursive=True))