Created
May 6, 2021 00:18
-
-
Save dmcnulla/94a5ff9a945d414652ee74df68b61ae8 to your computer and use it in GitHub Desktop.
converts postman export files to http files (used by IntelliJ plugin)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from os import listdir | |
BASE_PATH = '/Users/david.mcnulla/Documents' | |
if __name__ == '__main__': | |
for file in [f"{BASE_PATH}/{file_name}" for file_name in listdir(BASE_PATH) if file_name.endswith('.json')]: | |
with open(file) as json_file: | |
data = json.load(json_file) | |
items = data['item'] | |
if isinstance(items, list): | |
print(f"#{file}") | |
for item in data['item']: | |
print(f"\n\n### {item['name']}") | |
method = item['request']['method'] | |
print(f"{method} {item['request']['url']['raw'].replace('5080', '5000')}") | |
for header in item['request']['header']: | |
print(f"{header['key']}: {header['value']}") | |
print("\n") | |
if method in ['POST', 'PUT']: | |
try: | |
body = json.loads(item['request']['body']['raw']) | |
print(json.dumps(body, indent=2)) | |
except Exception as error_obj: | |
print(error_obj) | |
print('\n') | |
print('\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment