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