def compare_new_vs_old_item(self) -> bool: """Print the difference between this item and the database.""" # Create JSON out object to compare item_properties = ItemProperties(**self.item_dict) current_json = item_properties.construct_json() # Try get existing entry (KeyError means it doesn't exist - aka a new item) try: existing_json = self.all_db_items[self.item_id] except KeyError: print(f">>> compare_json_files: NEW ITEM: {item_properties.id}") print(current_json) self.item_dict["last_updated"] = datetime.now( timezone.utc).strftime("%Y-%m-%d") return if current_json == existing_json: self.item_dict["last_updated"] = self.all_db_items[ self.item_id]["last_updated"] return ddiff = DeepDiff(existing_json, current_json, ignore_order=True, exclude_paths="root['icon']") if ddiff: print( f">>> compare_json_files: CHANGED ITEM: {item_properties.id}: {item_properties.name}" ) print(ddiff) self.item_dict["last_updated"] = datetime.now( timezone.utc).strftime("%Y-%m-%d")
def check_duplicate_item(self) -> ItemProperties: """Determine if this is a duplicate item. :return: An ItemProperties object. """ # Start by setting the duplicate property to False self.item_dict["duplicate"] = False # Create an ItemProperties object item_properties = ItemProperties(**self.item_dict) # Check list of known bad duplicates if str(item_properties.id) in self.duplicate_items: duplicate_status = self.duplicate_items[str( item_properties.id)]["duplicate"] self.item_dict["duplicate"] = duplicate_status return None # Check noted, placeholder and noted properties # If any of these properties, it must be a duplicate if item_properties.stacked or item_properties.noted or item_properties.placeholder: self.item_dict["duplicate"] = True return None # Set the item properties that we want to compare correlation_properties = {"name": False, "wiki_name": False} # Loop the list of currently (already processed) items for known_item in self.known_items: # Skip when cache names are not the same if item_properties.name != known_item.name: continue # Check equality of each correlation property for cprop in correlation_properties: if getattr(item_properties, cprop) == getattr(known_item, cprop): correlation_properties[cprop] = True # Check all values in correlation properties are True correlation_result = all( value is True for value in correlation_properties.values()) # If name and wiki_name match, set duplicate property to True if correlation_result: item_properties.duplicate = True self.item_dict["duplicate"] = True return item_properties # If wiki_name is None, but cache names match... # The item must also be a duplicate if not item_properties.wiki_name: item_properties.duplicate = True self.item_dict["duplicate"] = True return item_properties # If we made it this far, no duplicates were found item_properties.duplicate = False self.item_dict["duplicate"] = False return item_properties
def validate_item(self): """Use the schema-items.json file to validate the populated item.""" # Create JSON out object to validate item_properties = ItemProperties(**self.item_dict) current_json = item_properties.construct_json() # Validate object with schema attached v = validator.MyValidator(self.schema_data) v.validate(current_json) # Print any validation errors if v.errors: print(v.errors) exit(1) assert v.validate(current_json)
def check_duplicate_item(self) -> ItemProperties: """Determine if this is a duplicate item. :return: An ItemDeinition object. """ # Start by setting the duplicate property to False self.item_dict["duplicate"] = False # Create an ItemProperties object item_properties = ItemProperties(**self.item_dict) # Set the item properties that we want to compare correlation_properties = { "wiki_name": False, "noted": False, "placeholder": False, "equipable": False, "equipable_by_player": False, "equipable_weapon": False } # Loop the list of currently (already processed) items for known_item in self.known_items: # Do a quick name check before deeper inspection if item_properties.name != known_item.name: continue # If the cache names are equal, do further inspection for cprop in correlation_properties: if getattr(item_properties, cprop) == getattr(known_item, cprop): correlation_properties[cprop] = True # Check is all values in correlation properties are True correlation_result = all( value is True for value in correlation_properties.values()) if correlation_result: self.item_dict["duplicate"] = True return item_properties
def export_item_to_json(self): """Export item to JSON, if requested.""" item_properties = ItemProperties(**self.item_dict) output_dir = Path(config.DOCS_PATH, "items-json") item_properties.export_json(True, output_dir)
def generate_item_object(self): """Generate the `ItemProperties` object from the item_dict dictionary.""" self.item_properties = ItemProperties(**self.item_dict)