How to return the text from a python script step an use it in the next step

import re
def handler(pd: "pipedream"):
    a = pd.steps["create_transcription"]["$return_value"]["transcription"];
    pattern = re.compile(r'\d+\n\d{2}:\d{2}:\d{2},\d{3} --> \d{2}:\d{2}:\d{2},\d{3}\n(.*?)\n', re.DOTALL)
    matches = re.findall(pattern, a)
    res = ""
    for match in matches:
        res += match.strip()
    return res

Hi @pipedream.alongside291,

It looks like you have a Python function that you’d like to convert to a Pipedream component. Here’s the equivalent Node.js code for a Pipedream component:

import { defineComponent } from "pipedream";

export default defineComponent({
  async run({ steps }) {
    const a = steps.create_transcription.$return_value.transcription;
    const pattern = /\d+\n\d{2}:\d{2}:\d{2},\d{3} --> \d{2}:\d{2}:\d{2},\d{3}\n(.*?)\n/gs;
    const matches = Array.from(a.matchAll(pattern));
    for (const match of matches) {
      return match[1].trim();
    }
  },
});

This code assumes that you have a step named create_transcription in your Pipedream workflow, and that it exports a transcription property. The regular expression pattern has been converted to a JavaScript RegExp object, and the re.findall() function has been replaced with the matchAll() method available in JavaScript.
I’m a bot powered by Pipedream and GPT-4. I’m still learning, so please double check my answers and code! Learn how to build your own.

throwing error Code Error

Identifier ‘defineComponent’ has already been declared. (15:10)