Generating Labels and QR Codes from Scripts

It is possible to generate labels from scripts.

The simplest form of generating labels consist of:

  1. A step which generates or pulls information about the labels.

  2. A script step which generates labels based on information from step #1 above.

1. Generate or gather label information

This step involves pulling relevant information for the labels. This can be generated through:

  • Assign a pandas dataframe to records_to_create to create new records

  • Get record information from step by using seal.get_step_records(step_id, ?step_version)

Example

The code below generates random numbers for machine XXXX, YYYY, and ZZZZ and creates records.

import random

data = [
    {
        'Machine': 'XXXX',
        'Reading': random.randrange(1,100)
    },
    {
        'Machine': 'YYYY',
        'Reading': random.randrange(1,100)
    },
    {
        'Machine': 'ZZZZ',
        'Reading': random.randrange(1,100)
    },
]

records_to_create = pd.DataFrame.from_records(data)

2. Generating labels from a script

This step involves:

  • Reading in all sample records produced by the previous step

  • Creating a QR code label pointing to the sample URLs within Seal

  • Creating new records including the labels and sample data

Example (continued)

The script will generate .png files for each individual record that can be printed.

import subprocess
subprocess.check_output('pip install qrcode[pil]'.split())

import qrcode

previous_records = seal.get_previous_step_records()

label_data = []

for record in previous_records:
    id = record["id"]
    machine = record["fields"]["Machine"]["value"]
    reading = record["fields"]["Reading"]["value"]

    label_filepath = f"{id}.png" # Use a unique ID
    label_filename = f"{machine}_{reading}_label.png"

    qrcode.make(f"https://platform.seal.run/o/seal/{id}").save(label_filepath)
    label_file_id = seal.upload_file(file_path=label_filepath, file_name=label_filename)["fileId"]

    label_data.append({
        "label": [label_file_id],
        "Machine": machine,
        "Reading": reading,
    })

records_to_create = pd.DataFrame.from_records(label_data)

What label printer is most compatible with Seal?

In our experience, we recommend Zebra printers as they are easy to set up, however almost all label printers are compatible with Seal - speak to team to find out more.

Last updated