# Path: dataimporter/tools.py
# def find_or_create_item(L, name, subitems_name=None, error_absent=False):
#     try:
#         return list_find(L, lambda x: x['name'] == name)
#     except StopIteration:
#         if not error_absent:
#             d = {'id': genid(), 'name': name}
#             if subitems_name:
#                 d[subitems_name] = []
#             L.append(d)
#             return d
#         else:
#             raise
# 
# def changelog(*args, **kwargs):
#     print(*args, **kwargs, file=sys.stderr)
# 
# Path: dataimporter/fixer.py
# class WowToolsFixer:
#     """Base class for Wowtools-based data fixers."""
#     load_files = False
# 
#     def __init__(self, *args, build=None):
#         self.build = build
#         self._store_init(*args)
#         if self.load_files:
#             self.wt_files = {
#                 int(e['ID']): e for e in self.wt_get_table('files')
#             }
# 
#     def _store_init(self, *args):
#         raise NotImplementedError
# 
#     def run(self):
#         raise NotImplementedError
# 
#     def wt_get_table(self, table_name):
#         return wowtools.get_table(table_name, self.build)
# 
#     def get_icon_name(self, icon_id: int):
#         assert self.load_files
#         icon_name = str(icon_id)
#         if icon_id in self.wt_files:
#             icon_path = self.wt_files[icon_id]['Path']
#             if 'encrypted' not in icon_path:
#                 icon_name = icon_path.split('/')[-1].rsplit('.', 1)[0].lower()
#                 icon_name = icon_name.replace(' ', '-')
# 
#         return icon_name


from .tools import find_or_create_item, changelog
from .fixer import WowToolsFixer
    1738,  # Defender Illona
    1739,  # Vivianne
    1740,  # Aeda Brightdawn
    1741,  # Leorajh

    # Venthyr Ember Court
    2446,  # Baroness Vashj
    2447,  # Lady Moonberry
    2448,  # Mikanikos
    2449,  # The Countess
    2450,  # Alexandros Mograine
    2451,  # Hunt-Captain Korayn
    2452,  # Polemarch Adrestes
    2453,  # Rendle and Cudgelface
    2454,  # Choofa
    2455,  # Cryptkeeper Kassir
    2456,  # Droman Aliothe
    2457,  # Grandmaster Vole
    2458,  # Kleia and Pelagos
    2459,  # Sika
    2460,  # Stonehead
    2461,  # Plague Deviser Marileth

    # Necrolord Abomination Factory
    2462,  # Stitchmasters
]


def fcat(dct, cat=None):
    if cat is not None:

# Path: dataimporter/tools.py
# def find_or_create_item(L, name, subitems_name=None, error_absent=False):
#     try:
#         return list_find(L, lambda x: x['name'] == name)
#     except StopIteration:
#         if not error_absent:
#             d = {'id': genid(), 'name': name}
#             if subitems_name:
#                 d[subitems_name] = []
#             L.append(d)
#             return d
#         else:
#             raise
# 
# def changelog(*args, **kwargs):
#     print(*args, **kwargs, file=sys.stderr)
# 
# Path: dataimporter/fixer.py
# class WowToolsFixer:
#     """Base class for Wowtools-based data fixers."""
#     load_files = False
# 
#     def __init__(self, *args, build=None):
#         self.build = build
#         self._store_init(*args)
#         if self.load_files:
#             self.wt_files = {
#                 int(e['ID']): e for e in self.wt_get_table('files')
#             }
# 
#     def _store_init(self, *args):
#         raise NotImplementedError
# 
#     def run(self):
#         raise NotImplementedError
# 
#     def wt_get_table(self, table_name):
#         return wowtools.get_table(table_name, self.build)
# 
#     def get_icon_name(self, icon_id: int):
#         assert self.load_files
#         icon_name = str(icon_id)
#         if icon_id in self.wt_files:
#             icon_path = self.wt_files[icon_id]['Path']
#             if 'encrypted' not in icon_path:
#                 icon_name = icon_path.split('/')[-1].rsplit('.', 1)[0].lower()
#                 icon_name = icon_name.replace(' ', '-')
# 
#         return icon_name


# Path: dataimporter/factions.py
from .tools import find_or_create_item, changelog
from .fixer import WowToolsFixer

    1738,  # Defender Illona
    1739,  # Vivianne
    1740,  # Aeda Brightdawn
    1741,  # Leorajh

    # Venthyr Ember Court
    2446,  # Baroness Vashj
    2447,  # Lady Moonberry
    2448,  # Mikanikos
    2449,  # The Countess
    2450,  # Alexandros Mograine
    2451,  # Hunt-Captain Korayn
    2452,  # Polemarch Adrestes
    2453,  # Rendle and Cudgelface
    2454,  # Choofa
    2455,  # Cryptkeeper Kassir
    2456,  # Droman Aliothe
    2457,  # Grandmaster Vole
    2458,  # Kleia and Pelagos
    2459,  # Sika
    2460,  # Stonehead
    2461,  # Plague Deviser Marileth

    # Necrolord Abomination Factory
    2462,  # Stitchmasters
]


def fcat(dct, cat=None):
    if cat is not None:

        res = find_or_create_item(dct, cat, 'factions')