""" 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__": catalog = '\n\n\n' # Add head stuffs catalog += '\n\nOBUS Catalog\n' catalog += '\n' catalog += '\n' catalog += '\n' catalog += '\n' # Add scroll to top button catalog += '\n
\n
\n' catalog += '\n
\n
\n' # Add header catalog += '
\n
\n
\nZeus logo\n' catalog += '\n
\n
\n
\n

O.B.U.S. Catalog

\n' catalog += '
\n
\n

August 2020

\n
\n
\n' # Add page title catalog += '
\n

OBUS catalog

\n
\n\n
\n' # Add introduction and overview catalog += '
\n
\n

Controllers

\n' catalog += json_to_multi_html('controllers.json') + '\n
\n' catalog += '
\n
\n

Input modules

\n' catalog += json_to_multi_html('inputs.json') + '\n
\n' catalog += '
\n
\n

Output modules

\n' catalog += json_to_multi_html('outputs.json') + '\n
\n' catalog += '
\n
\n

Panic modules

\n' catalog += json_to_multi_html('panics.json') + '\n
\n' # Add footer and closing tags catalog += '
\n\n\n' # print(catalog) with open('catalog_test.html', 'w') as test_file: test_file.write(catalog)