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

@ -1,234 +1,246 @@
{ {
"definitions": {}, "definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://example.com/object1658520065.json", "$id": "https://example.com/object1658520065.json",
"title": "Root", "title": "Root",
"type": "object", "type": "object",
"required": [ "required": [
"license", "license",
"authors", "authors",
"categories", "categories",
"sites" "sites"
], ],
"properties": { "properties": {
"license": { "license": {
"$id": "#root/license", "$id": "#root/license",
"title": "License", "title": "License",
"type": "array", "type": "array",
"default": [], "default": [],
"items":{ "items": {
"$id": "#root/license/items", "$id": "#root/license/items",
"title": "Items", "title": "Items",
"type": "string", "type": "string",
"default": "", "default": "",
"examples": [ "examples": [
"Copyright (C) 2025 Micah Hoffman" "Copyright (C) 2025 Micah Hoffman"
], ],
"pattern": "^.*$" "pattern": "^.*$"
} }
}, },
"authors": { "authors": {
"$id": "#root/authors", "$id": "#root/authors",
"title": "Authors", "title": "Authors",
"type": "array", "type": "array",
"default": [], "default": [],
"items":{ "items": {
"$id": "#root/authors/items", "$id": "#root/authors/items",
"title": "Items", "title": "Items",
"type": "string", "type": "string",
"default": "", "default": "",
"examples": [ "examples": [
"WebBreacher" "WebBreacher"
], ],
"pattern": "^.*$" "pattern": "^.*$"
} }
}, },
"categories": { "categories": {
"$id": "#root/categories", "$id": "#root/categories",
"title": "Categories", "title": "Categories",
"type": "array", "type": "array",
"default": [], "default": [],
"items":{ "items": {
"$id": "#root/categories/items", "$id": "#root/categories/items",
"title": "Items", "title": "Items",
"type": "string", "type": "string",
"default": "", "default": "",
"examples": [ "examples": [
"archived" "archived"
], ],
"pattern": "^.*$" "pattern": "^.*$"
} }
}, },
"sites": { "sites": {
"$id": "#root/sites", "$id": "#root/sites",
"title": "Sites", "title": "Sites",
"type": "array", "type": "array",
"default": [], "default": [],
"items":{ "items": {
"$id": "#root/sites/items", "$id": "#root/sites/items",
"title": "Items", "title": "Items",
"type": "object", "type": "object",
"required": [ "required": [
"name", "name",
"uri_check", "uri_check",
"e_code", "e_code",
"e_string", "e_string",
"m_string", "m_string",
"m_code", "m_code",
"known", "known",
"cat" "cat"
], ],
"properties": { "properties": {
"name": { "name": {
"$id": "#root/sites/items/name", "$id": "#root/sites/items/name",
"title": "Name", "title": "Name",
"type": "string", "type": "string",
"default": "", "default": "",
"examples": [ "examples": [
"101010.pl" "101010.pl"
], ],
"pattern": "^.*$" "pattern": "^.*$"
}, },
"uri_check": { "uri_check": {
"$id": "#root/sites/items/uri_check", "$id": "#root/sites/items/uri_check",
"title": "Uri_check", "title": "Uri_check",
"type": "string", "type": "string",
"default": "", "default": "",
"examples": [ "examples": [
"https://101010.pl/@{account}" "https://101010.pl/@{account}"
], ],
"pattern": "^.*$" "pattern": "^.*$"
}, },
"post_body": { "uri_pretty": {
"$id": "#root/sites/items/post_body", "$id": "#root/sites/items/uri_pretty",
"title": "Post_body", "title": "Uri_pretty",
"type": "string", "type": "string",
"default": "", "default": "",
"examples": [ "examples": [
"" "https://101010.pl/@{account}"
], ],
"pattern": "^.*$" "pattern": "^.*$"
}, },
"strip_bad_char": { "post_body": {
"$id": "#root/sites/items/strip_bad_char", "$id": "#root/sites/items/post_body",
"title": "Strip_bad_char", "title": "Post_body",
"type": "string", "type": "string",
"default": "", "default": "",
"examples": [ "examples": [
"." ""
], ],
"pattern": "^.*$" "pattern": "^.*$"
}, },
"e_code": { "headers": {
"$id": "#root/sites/items/e_code", "$id": "#root/sites/items/headers",
"title": "E_code", "title": "Headers",
"type": "integer", "type": "object",
"default": "", "default": [],
"examples": [ "items": {
200 "$id": "#root/sites/items/headers/items",
], "title": "Items",
"pattern": "^.*$" "type": "string",
}, "default": "",
"e_string": { "examples": [
"$id": "#root/sites/items/e_string", {
"title": "E_string", "accept": "text/html"
"type": "string", }
"default": "", ],
"examples": [ "pattern": "^.*$"
"@101010.pl" }
], },
"pattern": "^.*$" "strip_bad_char": {
}, "$id": "#root/sites/items/strip_bad_char",
"m_string": { "title": "Strip_bad_char",
"$id": "#root/sites/items/m_string", "type": "string",
"title": "M_string", "default": "",
"type": "string", "examples": [
"default": "", "."
"examples": [ ],
"The page you are looking for isn't here." "pattern": "^.*$"
], },
"pattern": "^.*$" "e_code": {
}, "$id": "#root/sites/items/e_code",
"m_code": { "title": "E_code",
"$id": "#root/sites/items/m_code", "type": "integer",
"title": "M_code", "default": "",
"type": "integer", "examples": [
"default": "", 200
"examples": [ ],
404 "pattern": "^.*$"
], },
"pattern": "^.*$" "e_string": {
}, "$id": "#root/sites/items/e_string",
"known": { "title": "E_string",
"$id": "#root/sites/items/known", "type": "string",
"title": "Known", "default": "",
"type": "array", "examples": [
"default": [], "@101010.pl"
"items":{ ],
"$id": "#root/sites/items/known/items", "pattern": "^.*$"
"title": "Items", },
"type": "string", "m_string": {
"default": "", "$id": "#root/sites/items/m_string",
"examples": [ "title": "M_string",
"szekspir" "type": "string",
], "default": "",
"pattern": "^.*$" "examples": [
} "The page you are looking for isn't here."
}, ],
"cat": { "pattern": "^.*$"
"$id": "#root/sites/items/cat", },
"title": "Cat", "m_code": {
"type": "string", "$id": "#root/sites/items/m_code",
"default": "", "title": "M_code",
"examples": [ "type": "integer",
"social" "default": "",
], "examples": [
"pattern": "^.*$" 404
}, ],
"valid": { "pattern": "^.*$"
"$id": "#root/sites/items/valid", },
"title": "Valid", "known": {
"type": "boolean", "$id": "#root/sites/items/known",
"examples": [ "title": "Known",
true "type": "array",
], "default": [],
"default": "" "items": {
}, "$id": "#root/sites/items/known/items",
"protection": { "title": "Items",
"$id": "#root/sites/items/protection", "type": "string",
"title": "Protection", "default": "",
"type": "array", "examples": [
"default": [], "szekspir"
"items":{ ],
"$id": "#root/sites/items/protection/items", "pattern": "^.*$"
"title": "Items", }
"type": "string", },
"default": "", "cat": {
"examples": [ "$id": "#root/sites/items/cat",
"cloudflare", "captcha" "title": "Cat",
], "type": "string",
"pattern": "^.*$" "default": "",
} "examples": [
}, "social"
"headers": { ],
"$id": "#root/sites/items/headers", "pattern": "^.*$"
"title": "Headers", },
"type": "object", "valid": {
"default": [], "$id": "#root/sites/items/valid",
"items":{ "title": "Valid",
"$id": "#root/sites/items/headers/items", "type": "boolean",
"title": "Items", "examples": [
"type": "string", true
"default": "", ],
"examples": [ "default": ""
{"accept": "text/html"} },
], "protection": {
"pattern": "^.*$" "$id": "#root/sites/items/protection",
} "title": "Protection",
} "type": "array",
} "default": [],
} "items": {
"$id": "#root/sites/items/protection/items",
} "title": "Items",
} "type": "string",
} "default": "",
"examples": [
"cloudflare",
"captcha"
],
"pattern": "^.*$"
}
}
}
}
}
}
}

File diff suppressed because it is too large Load Diff