-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrelease0_1.py
129 lines (113 loc) · 3.75 KB
/
release0_1.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import json
import re
import sys
from colorama import Fore
import click
import urllib3
def basic_file_read(file, json_file, ignore):
"""This is the main fnuction that reads from a file"""
try:
file_data = open(file, "r", encoding="utf-8")
pattern = re.findall(r"https?:[a-zA-Z0-9_.+-/#~]+", file_data.read())
list_of_status = []
for l_e in pattern:
q_e = l_e.strip()
if ignore != q_e:
list_of_status.append(test_request(q_e, json_file))
return list_of_status
except OSError:
print(
"The file cannot be opened! Make sure this file can be read and is legit."
)
sys.exit(1)
def test_request(q_e, json_file):
"""Tests a request with the arguments passed"""
try:
h_p = urllib3.PoolManager()
req = h_p.request("HEAD", q_e)
if not json_file:
if req.status == 200:
print(Fore.GREEN + f"{q_e} passes with {req.status}!")
elif req.status == 403:
print(Fore.WHITE + f"{q_e} looks sus, it returned {req.status}")
else:
print(Fore.RED + f"{q_e} is dead, as it returned {req.status}")
return (0, req.status)
return (0, req.status)
else:
conv = {"url": q_e, "status": req.status}
print(conv)
return(0, req.status)
except:
print("Unknown Error: " + str(sys.exc_info()[0]))
return (-1,1000)
def telescope_urls(q_e, json_file=None):
"""Unique Function for Telescope"""
h_p = urllib3.PoolManager()
req = h_p.request("HEAD", q_e)
try:
if not json_file:
if req.status == 200:
print(Fore.GREEN + f"{q_e} passes with {req.status}!")
elif req.status == 403:
print(Fore.WHITE + f"{q_e} looks sus, it returned {req.status}")
else:
print(Fore.RED + f"{q_e} is dead, as it returned {req.status}")
return 0
return 0
else:
conv = {"url": q_e, "status": req.status}
print(conv)
return 0
except:
print("Unknown Error: " + str(sys.exc_info()[0]))
return -1
@click.group()
def cli():
"""The main function to invoke click"""
pass
@cli.command("file")
@click.argument("file")
@click.option("--json", is_flag=True)
@click.option("--ignore", default=None, type=str)
def file_reader(file, json_file, ignore):
"""this reads URL links from a file!"""
q_e = False
if json_file:
q_e = True
a_e = basic_file_read(file, q_e, ignore)
for x_e in list:
if a_e[x_e][0] != 0:
sys.exit(a_e[x_e][0])
return a_e[0][1]
@cli.command("url")
@click.argument("url")
@click.option("--json", is_flag=True)
def url_reader(url, json_file):
"""this reads a URL that you pass as an argument!"""
q_e = False
if json_file:
q_e = True
a_e = test_request(str(url), q_e)
if a_e[0] != 0:
sys.exit(a_e[0])
else:
sys.exit(a_e[1])
@cli.command("telescope")
def telescope_reader():
"""Unique for Telescope"""
h_e = urllib3.PoolManager()
telescope_str = "http://localhost:3000/posts"
req = h_e.request("GET", telescope_str)
try:
posts = json.loads(req.data)
for post in posts:
telescope_urls(f"{telescope_str}/{post['id']}")
except urllib3.exceptions.MaxRetryError as e_e:
print(str(e_e))
@cli.command("version")
def version_check():
"""Returns you the version number of this code"""
print(Fore.BLUE + "Version 0.1")
if __name__ == "__main__":
cli()