-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist2collection.py
More file actions
65 lines (47 loc) · 1.62 KB
/
list2collection.py
File metadata and controls
65 lines (47 loc) · 1.62 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
#!/usr/bin/python3
####################
################
### n3wadm1n #####
### Euribot #####
#####################
import readline,json,time,os
readline.set_completer_delims(' \t\n=')
readline.parse_and_bind("tab: complete")
def generate_postman_request(method, host, endpoint):
url = f"https://{host}{endpoint}"
request = {
"header": [
{"key": "User-Agent", "value": "curl/7.74.0"},
{"key": "Accept", "value": "*/*"}
],
"url": url,
"method": method,
"body": None
}
return request
host = input("Enter the Host (eg. example.com): ")
collection_name = input("Enter the collection's name: ")
method_url_filename = input("Enter the filename that contains (METHOD PATH(ROUTE/ENDPOINT)), e.g. method_path.txt: ")
method_url_list = []
with open(method_url_filename, 'r') as file:
method_url_list = [line.strip().split(' ') for line in file.readlines()]
postman_items = []
for method, endpoint in method_url_list:
request_item = {
"name": f"Ref. {endpoint}",
"request": generate_postman_request(method, host, endpoint)
}
postman_items.append(request_item)
postman_collection = {
"info": {
"name": collection_name,
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": postman_items
}
json_filename = input("Enter the JSON's filename to output': ").replace(".json","").replace(".txt","")
with open(f'{json_filename}.json', 'w') as file:
json.dump(postman_collection, file, indent=4)
print(f"Done! Filename: {json_filename}.json")
time.sleep(5)
os.system('clear')