-
Notifications
You must be signed in to change notification settings - Fork 1
/
curl-redirects.py
executable file
·44 lines (33 loc) · 1.32 KB
/
curl-redirects.py
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
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
import os
import subprocess
from multiprocessing.pool import ThreadPool as Pool
base_path = "https://mini-org.netlify.app"
total_count = 0
broken_count = 0
org_paths = 'org_paths.txt'
broken_links = open("broken_links.txt", "w", newline="")
curl_redirect_results = open("curl_redirect_results.txt", "w", newline="")
with open(org_paths) as fp:
line = fp.readline()
while line:
path = line.strip()
try:
status_code = subprocess.check_output(
f'curl -L -s -o /dev/null -w "%{{http_code}}" {base_path}{path}', shell=True, universal_newlines=True).strip()
except:
print(f'Something failed curling the path: {path}')
if (status_code == "404"):
print(f'{status_code} response for {path}')
broken_links.write(base_path + path + "\n")
broken_count += 1
else:
print(f'{status_code} response for {path}')
curl_redirect_results.write(
f'{status_code} response for {path}' + "\n")
# proceed to next line/path
line = fp.readline()
total_count += 1
print("----------------------------------")
print(
f'{100 * round(float(total_count - broken_count)/float(total_count), 2)}% of pages migrated successfully! 404 results hit on {broken_count} paths.')