-
Notifications
You must be signed in to change notification settings - Fork 99
/
check_urls.py
34 lines (26 loc) · 901 Bytes
/
check_urls.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
import json
import requests
def check_urls(file_path):
with open(file_path, "r") as file:
data = json.load(file)
broken_urls = []
for package, details in data.items():
url = details.get("url")
if url:
try:
response = requests.head(url, allow_redirects=True)
if response.status_code != 200:
broken_urls.append((package, url, response.status_code))
except requests.RequestException as e:
broken_urls.append((package, url, str(e)))
return broken_urls
if __name__ == "__main__":
broken_urls = check_urls("list.json")
if broken_urls:
print("Broken URLs found:")
for package, url, status in broken_urls:
print(f"{package}: {url} (Status: {status})")
exit(1)
else:
print("All URLs are working.")
exit(0)