mirror of
https://github.com/WebBreacher/WhatsMyName.git
synced 2025-06-18 14:25:31 -04:00
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
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:
commit
b5acedaeb1
31
.github/workflows/sort-format-json.yml
vendored
Normal file
31
.github/workflows/sort-format-json.yml
vendored
Normal 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
|
71
scripts/sort_format_json.py
Normal file
71
scripts/sort_format_json.py
Normal 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.")
|
@ -16,7 +16,7 @@
|
|||||||
"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",
|
||||||
@ -32,7 +32,7 @@
|
|||||||
"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",
|
||||||
@ -48,7 +48,7 @@
|
|||||||
"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",
|
||||||
@ -64,7 +64,7 @@
|
|||||||
"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",
|
||||||
@ -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",
|
||||||
@ -164,7 +192,7 @@
|
|||||||
"title": "Known",
|
"title": "Known",
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"default": [],
|
"default": [],
|
||||||
"items":{
|
"items": {
|
||||||
"$id": "#root/sites/items/known/items",
|
"$id": "#root/sites/items/known/items",
|
||||||
"title": "Items",
|
"title": "Items",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@ -199,36 +227,20 @@
|
|||||||
"title": "Protection",
|
"title": "Protection",
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"default": [],
|
"default": [],
|
||||||
"items":{
|
"items": {
|
||||||
"$id": "#root/sites/items/protection/items",
|
"$id": "#root/sites/items/protection/items",
|
||||||
"title": "Items",
|
"title": "Items",
|
||||||
"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": "^.*$"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
15994
wmn-data.json
15994
wmn-data.json
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user