Commit 23fbf708 authored by Tobias Quathamer's avatar Tobias Quathamer

Reorganize ISO 3166-2 schema, data and validation

parent fb97712c
......@@ -44,16 +44,12 @@ for standard in standards:
# Read in the JSON file
with open("data/iso_" + standard + ".json") as json_file:
iso = json.load(json_file)
# Special case for ISO 3166-2
sort_key = "alpha_3"
if standard in ["3166-3", "15924"]:
sort_key = "alpha_4"
if standard == "3166-2":
for entry in iso[standard]:
for subset in entry["subsets"]:
subset["items"].sort(key=lambda item: item["code"])
else:
sort_key = "alpha_3"
if standard in ["3166-3", "15924"]:
sort_key = "alpha_4"
iso[standard].sort(key=lambda item: item[sort_key])
sort_key = "code"
iso[standard].sort(key=lambda item: item[sort_key])
# Write the sorted JSON file
with open("data/iso_" + standard + ".json", "w") as json_file:
json.dump(iso, json_file, ensure_ascii=False, indent=2, sort_keys=True)
......
This diff is collapsed.
......@@ -12,55 +12,28 @@
"type": "object",
"properties": {
"code": {
"description": "Two letter alphabetic code of the country",
"description": "Code of the country subset item",
"type": "string",
"pattern": "^[A-Z]{2}$"
"pattern": "^[A-Z]{2}-[A-Z0-9]+$"
},
"subsets": {
"description": "Subsets of the country",
"type": "array",
"items": {
"type": "object",
"properties": {
"items": {
"description": "Items of the country subset",
"type": "array",
"items": {
"type": "object",
"properties": {
"code": {
"description": "Code of the country subset item",
"type": "string",
"pattern": "^[A-Z]{2}-[A-Z0-9]+$"
},
"name": {
"description": "Name of the country subset item",
"type": "string",
"minLength": 1
},
"parent": {
"description": "Parent of the country subset item (optional)",
"type": "string",
"minLength": 1
}
},
"required": ["code", "name"],
"additionalProperties": false
}
},
"type": {
"description": "Type of subset of the country",
"type": "string"
}
},
"required": ["items", "type"],
"additionalProperties": false
}
"name": {
"description": "Name of the country subset item",
"type": "string",
"minLength": 1
},
"parent": {
"description": "Parent of the country subset item (optional)",
"type": "string",
"minLength": 1
},
"type": {
"description": "Type of subset of the country",
"type": "string"
}
},
"required": ["code", "subsets"],
"additionalProperties": false
}
}
},
"required": ["code", "name", "type"],
"additionalProperties": false
}
},
"additionalProperties": false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment