You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

22 lines
983 B

# -*- coding: utf-8 -*-
"""盘点现有 .bru 参数行 key + 钥匙"""
import os, re, io, sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
root = r'D:\code\crm-api-docs\商机模块'
BT = '`'
pat_key = re.compile(BT + r'(GET|POST) ([^' + BT + r']+)' + BT)
for dirpath, dirnames, filenames in os.walk(root):
for fn in sorted(filenames):
if not fn.endswith('.bru') or fn == 'folder.bru':
continue
rel = os.path.relpath(os.path.join(dirpath, fn), root)
txt = open(os.path.join(dirpath, fn), encoding='utf-8').read()
m = pat_key.search(txt)
keys = []
for mm in re.finditer(r'(params:query|body:form-urlencoded|body:json) \{([^}]*)\}', txt):
for line in mm.group(2).splitlines():
line = line.strip()
if line and ':' in line:
keys.append(line.split(':')[0].strip())
print(f'{rel} | {m.group(1)} {m.group(2)} | {", ".join(keys)}')