""" Script to generate the OBUS catalog from JSON files. """ import json def catalog_json_item_to_html(name: str, config: dict) -> str: # Make the section and title res = f'
\n

{name}

\n' # Add the item image and containers res += '
\n
\n
\n
\n' res += f'\n
\n
\n

{name}

\n
\n' # Add features res += '
\n
Features
\n
    \n' for feat in config['features']: res += f'
  • {feat}
  • \n' # Add descriptions res += '
\n
Description
\n' res += f'

{config["description"]}

\n' # Add applications res += '
Applications
\n
    \n' for appl in config['applications']: res += f'
  • {appl}
  • \n' res += '
\n
\n
\n' # Add electrical specs res += '
\n

electrical specs

\n
\n' res += '\n\n\n\n\n' res += '\n\n\n\n\n' for spec in config['el-specs'].keys(): res += f'\n\n' specs = config['el-specs'][spec] res += f'\n\n\n\n\n' # Add application note res += '
CharacteristicLimitsunit
mintypmax
{spec}{specs["min"]}{specs["typ"]}{specs["max"]}{specs["unit"]}
\n
\n

Application note

\n' res += f'

{config["app-note"]}

\n
\n' # Add document links res += '
\n

documents

\n\n
\n' # Add order codes res += '
\n

order codes

\n
\n\n' res += '\n\n\n\n' for code, desc in config['order-codes'].items(): res += f'\n\n\n\n' res += '
Descriptioncode
{desc}{code}
\n
\n
\n' # Add clsing tag res += '
' return res def json_to_multi_html(filename:str): res = '' with open(filename, 'r') as in_file: cat_items = json.load(in_file) for cat_item, cat_item_config in cat_items.items(): res += catalog_json_item_to_html(cat_item, cat_item_config) return res if __name__ == "__main__": print(json_to_multi_html('controllers.json')) print(json_to_multi_html('inputs.json')) print(json_to_multi_html('outputs.json')) print(json_to_multi_html('panics.json'))