-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
62 lines (47 loc) · 1.55 KB
/
main.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import asyncio
import httpx
from fake_useragent import UserAgent
settings = {
"timeout": 5,
}
headers = {
"user-agent": UserAgent().random,
"accept": "text/html"
}
urls = []
result = {
"success": [],
"warning": [],
"error": []
}
def load_urls():
with open('url.txt', 'r', encoding='utf-8') as file:
for line in file:
line = line.strip()
urls.append(line)
async def check_urls():
for url in urls:
async with httpx.AsyncClient() as client:
try:
response = await client.get(url, headers=headers, timeout=settings['timeout'])
if response.status_code == 200 or response.status_code == 301:
print('{0:<30} {1:>30}'.format(url, '\033[92mSUCCESS\033[0m'))
result['success'].append(url)
else:
print('{0:<30} {1:>30}'.format(url, '\033[93mWARNING\033[0m'))
result['warning'].append(url)
except Exception as e:
print('{0:<30} {1:>30}'.format(url, '\033[91mERROR\033[0m'))
result['error'].append(url)
def save_data():
success = "\n".join(result['success'])
warning = "\n".join(result['warning'])
error = "\n".join(result['error'])
open('data/success.txt', 'w').write(success)
open('data/warning.txt', 'w').write(warning)
open('data/error.txt', 'w').write(error)
if __name__ == '__main__':
load_urls()
print('{0:<30} {1:>20}'.format('Url', 'Status'))
asyncio.run(check_urls())
save_data()