mirror of
https://github.com/wolfswolke/DeathGarden_API_Rebirth.git
synced 2026-08-24 01:54:00 -05:00
Catalog stuff...
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import json
|
||||
import re
|
||||
|
||||
base_template = {
|
||||
"Result": []
|
||||
@@ -76,8 +77,17 @@ def normalize_data(json_data, prev_guid, next_guid, is_weapon, character_class):
|
||||
else:
|
||||
# normalized_data.pop("Faction")
|
||||
normalized_data["Faction"] = character_class
|
||||
if normalized_data["DisplayName"]:
|
||||
if re.match("(?!.*(?:Name|Title|NAME)).*", normalized_data["DisplayName"]):
|
||||
try:
|
||||
normalized_data["DisplayName"] = item_data.get("Properties", {}).get("DisplayName", {}).get(
|
||||
"SourceString")
|
||||
except AttributeError:
|
||||
normalized_data = None
|
||||
return normalized_data
|
||||
if not normalized_data["Id"] or not normalized_data["DisplayName"]:
|
||||
normalized_data = None
|
||||
return normalized_data
|
||||
if normalized_data:
|
||||
normalized_data_list.append(normalized_data)
|
||||
return normalized_data_list
|
||||
|
||||
29
Tools/null_remover.py
Normal file
29
Tools/null_remover.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import json
|
||||
|
||||
def has_null_value(data):
|
||||
if isinstance(data, list):
|
||||
return any(has_null_value(item) for item in data)
|
||||
elif isinstance(data, dict):
|
||||
return any(has_null_value(value) for value in data.values())
|
||||
else:
|
||||
return data is None
|
||||
|
||||
def remove_items_with_null(data):
|
||||
return [item for item in data if not has_null_value(item)]
|
||||
|
||||
# File path
|
||||
file_path = 'src/json/catalog/te-23ebf96c-27498-ue4-7172a3f5/catalog.json'
|
||||
|
||||
# Read JSON data from file
|
||||
with open(file_path, 'r') as file:
|
||||
json_data = json.load(file)
|
||||
|
||||
# Remove items with null values
|
||||
updated_json_data = remove_items_with_null(json_data)
|
||||
|
||||
# Save updated JSON data back to the file
|
||||
with open(file_path, 'w') as file:
|
||||
json.dump(updated_json_data, file, indent=4)
|
||||
|
||||
# Print the updated JSON data
|
||||
print(json.dumps(updated_json_data, indent=4))
|
||||
Reference in New Issue
Block a user