Skip to content

Commit

Permalink
UUID Gen added
Browse files Browse the repository at this point in the history
  • Loading branch information
theroyakash committed Nov 1, 2020
1 parent 737a104 commit 13b0bb7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
27 changes: 27 additions & 0 deletions placeholderfile/UUIDGenerator.py
Original file line number Diff line number Diff line change
@@ -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 + '-%$#@!&^*(){}[]><?/|'
self.result = ''.join(random.choice(letters) for i in range(length))

else:
self.result = 'Unknown UUID data-type mentioned'

return self.result
2 changes: 1 addition & 1 deletion placeholderfile/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Mention Version Number
__version__ = '1.1'
__version__ = '1.2'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
from os import path

__version__ = '1.1'
__version__ = '1.2'

here = path.abspath(path.dirname(__file__))

Expand Down

0 comments on commit 13b0bb7

Please sign in to comment.