Merge pull request #968 from 3xp0rt/sort-format
Some checks failed
Sort and Format JSON Files / Sort and Format JSON Files (push) Has been cancelled

Auto-sort and format wmn-data.json
This commit is contained in:
Micah Hoffman 2025-06-09 13:18:48 -04:00 committed by GitHub
commit b5acedaeb1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10049 additions and 7685 deletions

31
.github/workflows/sort-format-json.yml vendored Normal file
View File

@ -0,0 +1,31 @@
name: Sort and Format JSON Files
on:
push:
paths:
- 'wmn-data.json'
- 'wmn-data-schema.json'
jobs:
sort-and-format-json:
name: Sort and Format JSON Files
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Run Python sorting script
run: python scripts/sort_format_json.py
- name: Commit if changed
run: |
git config --global user.name "github-actions"
git config --global user.email "github-actions@github.com"
git add wmn-data.json wmn-data-schema.json
git diff --cached --quiet || git commit -m "chore: auto-sort and format JSON files"
git push

View File

@ -0,0 +1,71 @@
import json
data_path = 'wmn-data.json'
schema_path = 'wmn-data-schema.json'
def sort_array_alphabetically(arr):
return sorted(arr, key=str.lower)
def reorder_object_keys(obj, key_order):
reordered = {k: obj[k] for k in key_order if k in obj}
for k in obj:
if k not in key_order:
reordered[k] = obj[k]
return reordered
def sort_headers(site):
headers = site.get("headers")
if isinstance(headers, dict):
site["headers"] = dict(sorted(headers.items(), key=lambda item: item[0].lower()))
def load_and_format_json(path):
with open(path, 'r', encoding='utf-8') as f:
raw_content = f.read()
data = json.loads(raw_content)
formatted = json.dumps(data, indent=2, ensure_ascii=False)
return data, raw_content, formatted
data, data_raw, data_formatted = load_and_format_json(data_path)
schema, schema_raw, schema_formatted = load_and_format_json(schema_path)
changed = False
# Sort authors and categories
if isinstance(data.get('authors'), list):
data['authors'] = sort_array_alphabetically(data['authors'])
if isinstance(data.get('categories'), list):
data['categories'] = sort_array_alphabetically(data['categories'])
# Sort and reorder sites
site_schema = schema.get('properties', {}).get('sites', {}).get('items', {})
key_order = list(site_schema.get('properties', {}).keys())
if isinstance(data.get('sites'), list):
data['sites'].sort(key=lambda site: site.get('name', '').lower())
for site in data['sites']:
sort_headers(site)
data['sites'] = [reorder_object_keys(site, key_order) for site in data['sites']]
updated_data_formatted = json.dumps(data, indent=2, ensure_ascii=False)
# Write wmn-data.json if changed
if data_raw.strip() != updated_data_formatted.strip():
with open(data_path, 'w', encoding='utf-8') as f:
f.write(updated_data_formatted)
print("Updated and sorted wmn-data.json.")
changed = True
else:
print("wmn-data.json already formatted.")
# Write formatted wmn-data-schema.json if changed
if schema_raw.strip() != schema_formatted.strip():
with open(schema_path, 'w', encoding='utf-8') as f:
f.write(schema_formatted)
print("Formatted wmn-data-schema.json.")
changed = True
else:
print("wmn-data-schema.json already formatted.")
if not changed:
print("No changes made.")

View File

@ -99,6 +99,16 @@
], ],
"pattern": "^.*$" "pattern": "^.*$"
}, },
"uri_pretty": {
"$id": "#root/sites/items/uri_pretty",
"title": "Uri_pretty",
"type": "string",
"default": "",
"examples": [
"https://101010.pl/@{account}"
],
"pattern": "^.*$"
},
"post_body": { "post_body": {
"$id": "#root/sites/items/post_body", "$id": "#root/sites/items/post_body",
"title": "Post_body", "title": "Post_body",
@ -109,6 +119,24 @@
], ],
"pattern": "^.*$" "pattern": "^.*$"
}, },
"headers": {
"$id": "#root/sites/items/headers",
"title": "Headers",
"type": "object",
"default": [],
"items": {
"$id": "#root/sites/items/headers/items",
"title": "Items",
"type": "string",
"default": "",
"examples": [
{
"accept": "text/html"
}
],
"pattern": "^.*$"
}
},
"strip_bad_char": { "strip_bad_char": {
"$id": "#root/sites/items/strip_bad_char", "$id": "#root/sites/items/strip_bad_char",
"title": "Strip_bad_char", "title": "Strip_bad_char",
@ -205,30 +233,14 @@
"type": "string", "type": "string",
"default": "", "default": "",
"examples": [ "examples": [
"cloudflare", "captcha" "cloudflare",
], "captcha"
"pattern": "^.*$"
}
},
"headers": {
"$id": "#root/sites/items/headers",
"title": "Headers",
"type": "object",
"default": [],
"items":{
"$id": "#root/sites/items/headers/items",
"title": "Items",
"type": "string",
"default": "",
"examples": [
{"accept": "text/html"}
], ],
"pattern": "^.*$" "pattern": "^.*$"
} }
} }
} }
} }
} }
} }
} }

File diff suppressed because it is too large Load Diff