-2

I am trying to make a Python function of a given NodeJS function as my back-end is python based. The main issue is that I am unaware of the tools to use in this case.

I want to create the generateTemporaryGuid function in python.

NodeJS function:

// NodeJS code

import * as Chance from 'chance';    

private generateTemporaryGuid(seed: string, valid: number) {
    return new Chance(`${seed}${this.poolID}${Math.round(Date.now() / valid)}`).guid();
    }
}

The 'poolID' is generated using this function:

// NodeJS code

public generatePool(seed: string): void {
    const myID = chance.string({
      pool: 'abcdefgh0123456789',
      length: 18,
    });
    this.poolID = 'pool-${myID}';
}

I could create the python equivalent of this pool_id generating function using this code(correct me if I'm wrong):

# Python code

p = 'abcdefgh0123456789'
pool_id = 'pool-' + ''.join(random.sample(p, 18))

I understand that it is creating a new instance of 'Chance' then calling a guid() method on that instance.

I don't know the python equivalent of Chance. I can think of uuid.UUID module in python but it takes 32 or 64 bit hex digits.

1 Answers1

0

As you probably know it by now, Chance is used mainly for generating fixtures, specialy for automatic testing. An equivalent would be using "faker", it exists in python and nodejs too. You can find it here => https://pypi.org/project/Faker/

If it's just to generate a fake guid, then what you did is more that enough

millenion
  • 1,218
  • 12
  • 16