Skip to content

Commit 26e9cd6

Browse files
Add setup_script and 2 usefulibs
1 parent fafca65 commit 26e9cd6

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

usefulib/_usefulibs.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
Add your useful method here if you are contributing. Remember to add unit tests in tests.py :)
88
"""
99

10+
if __name__ == "__main__":
11+
import setup_script
12+
else:
13+
from . import setup_script
14+
15+
setup_script.SETUP() # If you need any setup scripts, write them in setup_script.py.
16+
1017
def reverse_string(string):
1118
""" @hamdivazim - Reverses a string. """
1219

@@ -79,4 +86,36 @@ def filter_by_condition(lst, condition: str):
7986
for i in lst:
8087
exec(f"if({condition}):result+=i")
8188

82-
return result
89+
return result
90+
91+
def generate_random_string(word_length):
92+
components = [string.ascii_letters, string.digits, "!@#$%&"]
93+
94+
chars = []
95+
96+
for clist in components:
97+
for item in clist:
98+
chars.append(item)
99+
100+
result = []
101+
102+
for i in range(word_length):
103+
rchar = random.choice(chars)
104+
result.append(rchar)
105+
106+
return "".join(result)
107+
108+
def generateUUID(version=4):
109+
if version < 1 or version > 5:
110+
raise ValueError(f"{version} is not a valid UUID version number (valid values are 1-5).")
111+
else:
112+
if version == 1:
113+
return uuid.uuid1()
114+
elif version == 2:
115+
return uuid.uuid2()
116+
elif version == 3:
117+
return uuid.uuid3()
118+
elif version == 4:
119+
return uuid.uuid4()
120+
elif version == 5:
121+
return uuid.uuid5()

usefulib/setup_script.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""
2+
usefulib v1.0
3+
Copyright Hamd Waseem (https://github.com/hamdivazim) under the GNU Public License 3.0.
4+
5+
https://github.com/hamdivazim/usefulib
6+
7+
In case your script needs any form of setup (e.g. imports) write them here.
8+
"""
9+
10+
def SETUP():
11+
""" @hamdivazim - Import libs for generate_random_string() and generateUUID() """
12+
import random
13+
import string
14+
import uuid

0 commit comments

Comments
 (0)