diff --git a/README.md b/README.md index eae2b68..f8a21a4 100644 --- a/README.md +++ b/README.md @@ -54,4 +54,17 @@ def downloadImageFromURL(url): filename = gn(suffix='.jpg', prefix=None, seed=None) image.save(filename) print(f'Image saved at {os.getcwd()}/{filename}') +``` + +# UUID Generator +placeholderfile can now generate UUIDs for databases. + +To be able to generate random 22 character length UUIDs use the following code: +```python +from placeholderfile.UUIDGenerator import UUIDGenerator + +generator = UUIDGenerator(dtype='str-major') # You can choose also 'int-major' for generating integer dominant UUID +uuid = generator.generate() + +print(uuid) ``` \ No newline at end of file diff --git a/placeholderfile/UUIDGenerator.py b/placeholderfile/UUIDGenerator.py new file mode 100644 index 0000000..ac5fbc8 --- /dev/null +++ b/placeholderfile/UUIDGenerator.py @@ -0,0 +1,27 @@ +import random +import string + +class UUIDGenerator: + + def __init__(self, dtype='str-major', seed=None): + self.dtype = dtype + if seed is not None: + self.seed = seed + else: + self.seed = random.randint(1, 200) + def generate(self): + if self.dtype == 'int-major': + self.result = [] + length = 22 + data = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '&', '-', '%', '#', '@'] + self.result = ''.join(random.choice(data) for i in range(length)) + + elif self.dtype == 'str-major': + length = 22 + letters = string.ascii_lowercase + string.ascii_uppercase + '-%$#@!&^*(){}[]>