-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtility.py
More file actions
74 lines (53 loc) · 1.81 KB
/
Utility.py
File metadata and controls
74 lines (53 loc) · 1.81 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import json
from dataclasses import dataclass, asdict, field
from typing import Dict
DATA_FILE = 'data.json'
@dataclass
class RequestOptions:
data: list[str] = field(default_factory=lambda: ["", ""])
connection_message: str = ""
cookies: str = ""
origin: str = ""
url: str = ""
variables: str = ""
def to_dict(self):
return asdict(self)
@staticmethod
def from_dict(d: dict):
return RequestOptions(**d)
def fetch_options(gate_name):
dict = json.loads(open(DATA_FILE).read())
if(dict.get(gate_name)):
return RequestOptions.from_dict(dict[gate_name])
return RequestOptions()
def save_options(gate_name, options, print_value=True):
dict = json.loads(open(DATA_FILE).read())
options_dict = options.to_dict()
dict[gate_name] = options_dict
if(print_value == True):
print(options_dict)
with open(DATA_FILE, "w") as file:
file.write(json.dumps(dict, indent=2))
def map_to_options(gate_name, args):
options = fetch_options(gate_name)
if args.connection_message != "":
options.connection_message = args.connection_message
if args.cookies != "":
options.cookies = args.cookies
if args.origin != "":
options.origin = args.origin
if args.url != "":
options.url = args.url
if args.data and len(args.data) > 0:
options.data[0] = args.data[0][0]
if args.data and len(args.data) > 1:
options.data[1] = args.data[1][0]
save_options(gate_name, options)
def variables_to_dict(variables):
variables_list = str.split(variables, " ")
variables_dict = {}
for key_value_pair in variables_list:
key = str.split(key_value_pair, ':')[0]
value = str.split(key_value_pair, ':')[1]
variables_dict[key] = value
return variables_dict