-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
68 lines (58 loc) · 1.82 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
63
64
65
66
67
68
"""
Main guy, gets Arguments and returns Result either printed on console or to the output arg
"""
import argparse
from http_client.client import HttpClient
from help import ARGUMENTS_PARSING, HELP_MISC
from progress_bar.progress_bar import ProgressBar
def setup_arg_parser():
"""
Sets up arguments parser
"""
parser = argparse.ArgumentParser(description=HELP_MISC["description"])
class store_dict_key_pair(argparse.Action):
"""
Gives Argparser an ability to store POST attrs
"""
def __call__(self, parser, namespace, values, option_string=None):
my_dict = {}
for kv in values.split(","):
k, v = kv.split("=")
my_dict[k] = v
setattr(namespace, self.dest, my_dict)
parser.add_argument("address", type=str, help=ARGUMENTS_PARSING["address"])
parser.add_argument(
"-output", metavar="-o", type=str, help=ARGUMENTS_PARSING["output"]
)
parser.add_argument(
"-method", metavar="-m", type=str, help=ARGUMENTS_PARSING["method"]
)
parser.add_argument(
"-timeout", metavar="-t", type=int, help=ARGUMENTS_PARSING["timeout"]
)
parser.add_argument(
"-body",
metavar="-b",
action=store_dict_key_pair,
help=ARGUMENTS_PARSING["body"],
)
parser.add_argument(
"-headers",
metavar="-he",
action=store_dict_key_pair,
help=ARGUMENTS_PARSING["header"],
)
parser.add_argument(
"-cookies",
metavar="-c",
action=store_dict_key_pair,
help=ARGUMENTS_PARSING["cookies"],
)
return parser
def main():
parser = setup_arg_parser()
args = parser.parse_args()
client = HttpClient(vars(args), progress_bar=ProgressBar())
client.fire()
if __name__ == "__main__":
main()