-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebsiteChecker.py
44 lines (36 loc) · 1.26 KB
/
websiteChecker.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
import csv
import requests
from fake_useragent import UserAgent
from http import HTTPStatus
def get_website(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 value == status_code:
description: str = f"{value} {value.name} {value.description}"
return description
return "(???) Unknown status code... "
def check_website(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 websites: "{website}"')
def main():
sites: list[str] = get_website("website.csv")
user_agent: str = get_user_agent()
for site in sites:
check_website(site, user_agent)
if __name__ == "__main__":
main()