Browse Source

Adding the ability to choose upper or lower case ID generation

master
Elia El Lazkani 2 years ago
parent
commit
126af19e87
  1. 3
      config/config.yaml
  2. 11
      shortenit/shortener.py

3
config/config.yaml

@ -10,4 +10,5 @@ Shortener:
# Even though this guarantees that the ID doesn't exist, this might inflict
# some performance hit.
check_duplicate_id: False
id_length: 32
id_length: 32
id_upper_case: False

11
shortenit/shortener.py

@ -11,21 +11,26 @@ class Shortener:
self.uuid = None
self.length = 32
self.check_duplicate = False
self.upper_case = False
self.configuration = configuration
self.init()
def init(self):
length = self.configuration.get('id_length', 32)
length = self.configuration.get("id_length", 32)
if length >= 32 or length <= 0:
self.length = 32
else:
self.length = length
self.check_duplicate = self.configuration.get(
'check_duplicate_id', False)
"check_duplicate_id", False)
self.upper_case = self.configuration.get(
"id_upper_case", False)
def generate_short_uuid(self):
short_uuid = uuid.uuid1().hex
return short_uuid.upper()[0:self.length]
if self.upper_case:
return short_uuid.upper()[0:self.length]
return short_uuid.lower()[0:self.length]
def check_uuid(self, short_uuid):
with Document(self.pointer_db, 'pointer') as pointer:

Loading…
Cancel
Save