I'm trying to create a SOP Word doc out of a JSON with the following structure:
{
"doc_id": "hydraulic-press",
"title": "Hydraulic Press",
"description": "Procedures for safe startup, operation, shutdown, and basic operator maintenance of the Hydraulic Press 3500.",
"sections": [
{
"section": "Know the Machine",
"steps": [
{
"description": "Identify the main components: main power switch, control panel, cycle start, cycle timer, pedal, temperature gauge, ram sensors and indicator lights, emergency stop (red button), crank handle/adjust mechanism, alignment plate, front tilt control, and output tray.",
"images": []
},...
And so forth. This is my helper function to build the word doc:
def build_doc(sop_json):
doc = Document()
# Title
if sop_json.get("title"):
doc.add_heading(sop_json["title"], level=0)
# Description
if sop_json.get("description"):
doc.add_paragraph(sop_json["description"])
# Sections
sections = sop_json.get("sections", [])
for section in sections:
section_title = section.get("section", "Untitled Section")
doc.add_heading(section_title, level=1)
steps = section.get("steps", [])
for step in steps:
para = doc.add_paragraph(step.get("description", ""), style="List Number")
for image_ref in step.get("images", []):
add_image_to_paragraph(para, image_ref)
return doc
It's almost perfect, except for the fact that the numbers for each step do not restart with each new section. So, for example, I have this:
Know the Machine
1. Identify the main components: main power switch, control panel, cycle start, cycle timer, pedal, temperature gauge, ram sensors and indicator lights, emergency stop (red button), crank handle/adjust mechanism, alignment plate, front tilt control, and output tray.
2. Note sensor behavior: sensors on the ram sometimes glitch; confirm their status by checking the indicator lights before and during operation.
Start Up
4. Power sequence: turn on the main switch, then the panel, then initiate cycle start at the panel.
5. Pre-start check: check oil levels before starting; LOW oil levels indicate problems and must be addressed prior to operation.
How do I get it to restart the numbering index with each section?