Debian Codegraph @

scripts/check_urls.py

raw
1 import requests
2 import glob
3 import re
4
5
6 def test_urls(files):
7 headers = {'User-Agent': 'Mozilla/5.0 (compatible; MSIE 6.0; Fiona CI check)'}
8
9 for fpath in files:
10 print(f"Processing: {fpath}")
11 with open(fpath) as f:
12
13 text = f.read()
14 urls = re.findall('(https?:\\/\\/[^\\s`>\'"()]+)', text)
15
16 for url in urls:
17 http_code = None
18 try:
19 r = requests.get(url, headers=headers)
20 http_code = r.status_code
21 warn = ''
22 if not http_code == 200:
23 warn = ' <--- !!!'
24 except Exception as e:
25 warn = str(e)
26
27 if len(warn) > 0:
28 print(f"\t {url} HTTP code: {http_code} {warn}")
29
30
31 print("Test URLs in documentation")
32 test_urls(glob.glob('**/*.rst', recursive=True))
33 print('')
34 print('Test URLs in code')
35 test_urls(glob.glob('fiona/**/*.py', recursive=True))