-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebsite_checker.py
More file actions
50 lines (38 loc) · 1.31 KB
/
website_checker.py
File metadata and controls
50 lines (38 loc) · 1.31 KB
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
45
46
47
48
49
50
# pip install requests
# pip install fake_useragent
import csv
import requests
from fake_useragent import UserAgent
from http import HTTPStatus
def get_websites(csv_path: str) -> list[str]:
websites: list[str] = []
with open(csv_path, 'r') as file:
reader = csv.reader(file)
for row in reader:
if 'https://' not in row[1]:
websites.append(f'https://{row[1]}')
else:
websites.append(row[1])
return websites
def get_user_agent() -> str:
ua = UserAgent()
return ua.firefox
def get_status_description(status_code: int) -> str:
for value in HTTPStatus:
if status_code == value:
description: str = f'({value} {value.name}) {value.description}'
return description
return '(???) Unknown status code ...'
def check_websites(website: str, user_agent):
try:
code: int = requests.get(website, headers={'User-Agent': user_agent}).status_code
print(website, get_status_description(code))
except Exception:
print(f'*** Could not get information for website: {website}')
def main():
sites: list[str] = get_websites('websites.csv')
user_agent: str = get_user_agent()
for site in sites:
check_websites(site, user_agent)
if __name__ == '__main__':
main()