diff --git a/README.md b/README.md index 2312665..7686274 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ def example(): multithread(example, 10) # func: example | threads: 10 | single: 50 seconds | multi: 5 seconds ``` -> image +> image ```py from dankware import multithread @@ -51,7 +51,7 @@ def example(num): multithread(example, 10, new_list) # input_one: list print(sum) ``` -> image +> image ```py from dankware import multithread @@ -66,7 +66,7 @@ def example(num1, num2): multithread(example, 10, list1, list2) # input_one: list1 | input_two: list2 ``` -> image +> image ```py from dankware import multithread @@ -80,20 +80,30 @@ def example(num1, num2): multithread(example, 10, new_list, 5, progress_bar=False) # input_two: 5 | disabled progress bar ``` -> image +> image

 

--- -# 🚨 Generate Random IPs 🚨 +# 🚨 Export Registry Keys 🚨 ```py -from dankware import random_ip -print(random_ip()) +import os +from dankware import export_registry_keys, is_admin + +# [NOTE]: this function requires admin privileges! + +export_path = "D:\\export.reg" +registry_root = r'HKEY_CURRENT_USER' +registry_path = r'Software\Google\Chrome\PreferenceMACs' +#export_path = os.path.join(os.environ['USERPROFILE'], 'Desktop', 'export.reg') + +export_registry_keys(registry_root, registry_path, recursive=True, export_path=export_path) ``` +> image -> image +> image

 

@@ -107,7 +117,7 @@ from dankware import err, clr try: value = 1/0 except: print(clr(err(sys.exc_info()), 2)) ``` -> image +> image

 

@@ -120,14 +130,27 @@ from dankware import github_downloads # full url > https://api.github.com/repos/EssentialsX/Essentials/releases/latest for url in github_downloads("EssentialsX/Essentials"): print(url) ``` -> image +> image ```py from dankware import github_file_selector # full url > https://api.github.com/repos/EssentialsX/Essentials/releases/latest for url in github_file_selector("EssentialsX/Essentials", "remove", ['AntiBuild', 'Discord', 'GeoIP', 'Protect', 'XMPP']): print(url) ``` -> image +> image + +

 

+ +--- + +# 🚨 Generate Random IPs 🚨 + +```py +from dankware import random_ip +print(random_ip()) +``` + +> image

 

@@ -138,38 +161,49 @@ for url in github_file_selector("EssentialsX/Essentials", "remove", ['AntiBuild' ```py from dankware import clr # default mode = 1 -# default colour = magenta +# default colour_one = white +# default colour_two = magenta print(clr("\n > Hey! Long time no see :)")) +#print(clr("\n > Hey! Long time no see :)", colour_one = white, colour_two = magenta)) +``` +> image + +```py +from dankware import clr, white, magenta +# default mode = 1 +# default colour_one = white +# default colour_two = magenta +print(clr("\n > Hey! Long time no see :)", colour_one = magenta, colour_two = white)) ``` -> image +> image ```py from dankware import clr print(clr("\n This is a string: True | This is an integer: False")) ``` -> image +> image ```py from dankware import clr, green, magenta # dankware now supports adding custom colours on both the text and the function itself! -# colour = green -print(clr(f"\n > {magenta}Purple{white} thinks he's better than everyone else :(", colour=green)) +# colour_two = green +print(clr(f"\n > {magenta}Purple{white} thinks he's better than everyone else :(", colour_two=green)) ``` -> image +> image ```py from dankware import clr # mode = 2 print(clr("\n > Error in sector [7] redirecting... | INTEGRITY_CHECK_SUCCESS: TRUE",2)) ``` -> image +> image ```py from dankware import clr # mode = 3 print(clr("\n > Is this a randomly coloured string: TRUE | As you can see it does not colour True/False",3)) ``` -> image +> image

 

@@ -198,21 +232,21 @@ from dankware import clr # mode = 4 print(clr(banner,4)) ``` -> image +> image ## ♦️ Align Banner (console center) ♦️ ```py from dankware import align print(align(banner)) # also works with single text line (even coloured) ``` -> image +> image ## ♦️ Align Coloured Banner ♦️ ```py from dankware import align, clr print(align(clr(banner,4))) ``` -> image +> image

 

@@ -272,7 +306,6 @@ print(fade(banner, "green-v")) ## ♦️ Cyan ♦️ ```py -from dankware import fade print(fade(banner, "cyan")) ``` > image diff --git a/dankware/__init__.py b/dankware/__init__.py index b94f165..6077166 100644 --- a/dankware/__init__.py +++ b/dankware/__init__.py @@ -9,6 +9,8 @@ import os import sys import time +import ctypes +import winreg import random import requests from datetime import datetime @@ -48,70 +50,69 @@ def multithread(function, threads: int = 1, input_one = None, input_two = None, progress_bar: bool = True) -> None: """ - input one/two can be any of these: None, List, Variable + > Please read the documentation on github before using this function! + Input one/two can be any of the following: None, List, Variable """ - futures = [] - executor = ThreadPoolExecutor(max_workers=threads) - one_isList = type(input_one) is list - two_isList = type(input_two) is list - if input_one is None: one_isNone = True - else: one_isNone = False - if input_two is None: two_isNone = True - else: two_isNone = False - - if one_isNone: - for _ in range(threads): futures.append(executor.submit(function)) - - elif two_isNone: - if one_isList: - for item in input_one: futures.append(executor.submit(function, item)) + try: + futures = [] + executor = ThreadPoolExecutor(max_workers=threads) + one_isList = type(input_one) is list + two_isList = type(input_two) is list + if input_one is None: one_isNone = True + else: one_isNone = False + if input_two is None: two_isNone = True + else: two_isNone = False + + if one_isNone: + for _ in range(threads): futures.append(executor.submit(function)) + + elif two_isNone: + if one_isList: + for item in input_one: futures.append(executor.submit(function, item)) + else: + for _ in range(threads): futures.append(executor.submit(function, input_one)) + + elif not one_isNone and not two_isNone: + if one_isList and two_isList: + if len(input_one) != len(input_two): + err_msg = clr(f"MULTITHREAD ERROR! - input_one({len(input_one)}) and input_two({len(input_two)}) do not have the same length!",2) + if len(input_one) < 50 and len(input_two) < 50: + err_msg += clr(f"\n > input_one = {str(input_one)}",2) + err_msg += clr(f"\n > input_two = {str(input_two)}",2) + raise ValueError(err_msg) + for index in range(len(input_one)): futures.append(executor.submit(function, input_one[index], input_two[index])) + elif one_isList: + for index in range(len(input_one)): futures.append(executor.submit(function, input_one[index], input_two)) + elif two_isList: + for index in range(len(input_two)): futures.append(executor.submit(function, input_one, input_two[index])) + elif not one_isList and not two_isList: + for _ in range(threads): futures.append(executor.submit(function, input_one, input_two)) + + if progress_bar: + with alive_bar(int(len(futures)), title='') as bar: + for future in as_completed(futures): + try: future.result(); bar() + except: bar() else: - for _ in range(threads): futures.append(executor.submit(function, input_one)) - - elif not one_isNone and not two_isNone: - if one_isList and two_isList: - if len(input_one) != len(input_two): - print(clr(f"\n > MULTITHREAD ERROR! - input_one({len(input_one)}) and input_two({len(input_two)}) do not have the same length!",2)) - if len(input_one) < 50 and len(input_two) < 50: - print(clr(f"\n > input_one = {str(input_one)}",2)) - print(clr(f"\n > input_two = {str(input_two)}",2)) - sys.exit(1) - for index in range(len(input_one)): futures.append(executor.submit(function, input_one[index], input_two[index])) - elif one_isList: - for index in range(len(input_one)): futures.append(executor.submit(function, input_one[index], input_two)) - elif two_isList: - for index in range(len(input_two)): futures.append(executor.submit(function, input_one, input_two[index])) - elif not one_isList and not two_isList: - for _ in range(threads): futures.append(executor.submit(function, input_one, input_two)) - - if progress_bar: - with alive_bar(int(len(futures)), title='') as bar: for future in as_completed(futures): - try: future.result(); bar() - except: bar() - else: - for future in as_completed(futures): - try: future.result() - except: pass + try: future.result() + except: pass + except: sys.exit(clr(err(sys.exc_info()), 2)) def github_downloads(user_repo: str) -> list: """ - - this function extracts download urls from latest release on github and returns as list - - Example Input: EXAMPLE/EXAMPLE ( from https://api.github.com/repos/EXAMPLE/EXAMPLE/releases/latest ) - - Example Output: ['https://github.com/EXAMPLE/EXAMPLE/releases/download/VERSION/EXAMPLE.TXT'] - + Extracts direct download urls from the latest release on github and returns it as a list + + - Example Input: EXAMPLE/EXAMPLE ( from https://api.github.com/repos/EXAMPLE/EXAMPLE/releases/latest ) + - Example Output: ['https://github.com/EXAMPLE/EXAMPLE/releases/download/VERSION/EXAMPLE.TXT'] """ urls = [] #if "https://api.github.com/repos/" not in url or "/releases/latest" not in url: - # print(clr(' > Invalid url! Must follow: "https://api.github.com/repos/NAME/NAME/releases/latest"',2)) - # sys.exit(1) + # raise ValueError(clr(' > Invalid url! Must follow: "https://api.github.com/repos/NAME/NAME/releases/latest"',2)) while True: try: response = requests.get(f"https://api.github.com/repos/{user_repo}/releases/latest").json(); break except: input(clr(" > Make sure you are connected to the Internet! Press [ENTER] to try again... ",2)) @@ -127,9 +128,11 @@ def github_file_selector(user_repo: str, filter_mode: str, name_list: list) -> l This function is used to filter the output from github_downloads() - user_repo = 'USER_NAME/REPO_NAME' ( from https://api.github.com/repos/USER_NAME/REPO_NAME/releases/latest ) - filter_mode = 'add' or 'remove' - name_list = list of names to be added or removed + - user_repo = 'USER_NAME/REPO_NAME' ( from https://api.github.com/repos/USER_NAME/REPO_NAME/releases/latest ) + - filter_mode = 'add' or 'remove' + - name_list = list of names to be added or removed + + __________________________________________________________________________________ Example output from github_downloads("EX_USER/EX_REPO"): [ 'https://github.com/EX_USER/EX_REPO/releases/download/VERSION/EXAMPLE.TXT' @@ -139,8 +142,8 @@ def github_file_selector(user_repo: str, filter_mode: str, name_list: list) -> l 'https://github.com/EX_USER/EX_REPO/releases/download/VERSION/TEST_2.TXT' 'https://github.com/EX_USER/EX_REPO/releases/download/VERSION/TEST_3.TXT' ] - - ================================================================================== + + __________________________________________________________________________________ Example Input: "EX_USER/EX_REPO", "add", ["EXAMPLE"] @@ -150,9 +153,9 @@ def github_file_selector(user_repo: str, filter_mode: str, name_list: list) -> l 'https://github.com/EX_USER/EX_REPO/releases/download/VERSION/EXAMPLE_3.TXT' ] - Note: Only urls with filenames containing "EXAMPLE" were returned. + - Note: Only urls with filenames containing "EXAMPLE" were returned. - ================================================================================== + __________________________________________________________________________________ Example Input: "EX_USER/EX_REPO", "remove", ["EXAMPLE"] @@ -162,7 +165,7 @@ def github_file_selector(user_repo: str, filter_mode: str, name_list: list) -> l 'https://github.com/EX_USER/EX_REPO/releases/download/VERSION/TEST_3.TXT' ] - Note: Only urls with filenames not containing "EXAMPLE" were returned. + - Note: Only urls with filenames not containing "EXAMPLE" were returned. """ @@ -180,8 +183,8 @@ def github_file_selector(user_repo: str, filter_mode: str, name_list: list) -> l def random_ip() -> str: """ - generates a random valid computer ip - [NOTE] https://github.com/robertdavidgraham/masscan/blob/master/data/exclude.conf + Generates a random valid computer ip + - Follows: https://github.com/robertdavidgraham/masscan/blob/master/data/exclude.conf """ while True: @@ -203,86 +206,174 @@ def random_ip() -> str: return ip -def clr(text: str, mode: int = 1, colour: str = magenta) -> str: +def is_admin() -> bool: """ + Checks if the current user has admin privileges and returns True if found else False + """ - this function colours special characters inside the 'chars' list - - mode: 1 | to display general text (default) - spl = magenta (default) / specified colour - text = white + try: return ctypes.windll.shell32.IsUserAnAdmin() + except: return False - mode: 2 | to display error messages - spl = white - text = red +'''def run_as_admin() -> None: - mode: 3 - spl = white - text = random + """ + Executes the script with admin privileges + """ - mode: 4 | to display banners - spl & text = random + ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1) + #sys.exit(clr("\n > Exiting original un-elevated script...",2))''' + +def export_registry_keys(registry_root: str, registry_path: str, recursive: bool = True, export_path: str = "export.reg") -> None: """ + Function to export registry keys with or without its subkeys and saves them to export_path + - Examples for registry_root: 'HKEY_CLASSES_ROOT', 'HKEY_CURRENT_USER', 'HKEY_LOCAL_MACHINE', 'HKEY_USERS', 'HKEY_CURRENT_CONFIG' + - Example for registry_path: r'Software\Google\Chrome\PreferenceMACs' + - recursive: True (subkeys saved) + - recursive: False (subkeys not saved) + - export_path: "exported.reg" (default) + """ - if mode != 3: - for _ in range(len(colours_to_replace)): - text = text.replace(colours_to_replace[_], colours_alt[_]) - else: - for _ in range(len(colours_to_replace)): - text = text.replace(colours_to_replace[_], '') - - # default - - if mode == 1: - text = text.replace("[",f"{colour}[{white}").replace("]",f"{colour}]{white}") - for char in chars: text = text.replace(char, f"{colour}{char}{white}") - for word in words_green: - replacement = green.join(list(word)) - text = text.replace(word, f"{green}{replacement}{white}") - for word in words_red: - replacement = red.join(list(word)) - text = text.replace(word, f"{red}{replacement}{white}") + try: - # for error messages + key_data = [] + key_map = { + 'HKEY_CLASSES_ROOT': winreg.HKEY_CLASSES_ROOT, + 'HKEY_CURRENT_USER': winreg.HKEY_CURRENT_USER, + 'HKEY_LOCAL_MACHINE': winreg.HKEY_LOCAL_MACHINE, + 'HKEY_USERS': winreg.HKEY_USERS, + 'HKEY_CURRENT_CONFIG': winreg.HKEY_CURRENT_CONFIG, + } + + if not export_path.endswith('.reg'): + raise ValueError(clr("Invalid Export Path! export_path must end with '.reg'",2)) + if registry_root not in key_map.keys(): + raise ValueError(clr(f"Invalid Registry Root! Use one of the following: {', '.join(key_map.keys())}",2)) + if not is_admin(): + raise RuntimeError(clr("Current user is not an administrator! Exporting registry keys requires admin privileges!",2)) + # If the current user is not an admin, relaunch the script with admin privileges + #run_as_admin() + + def exporter(key, registry_root, subkey_path, key_data, recursive) -> None: + + # Open the registry subkey + subkey = winreg.OpenKey(key, subkey_path, 0, winreg.KEY_READ | winreg.KEY_WOW64_64KEY) + # Get the number of subkeys and add the current subkey's path to the output list + subkey_count = winreg.QueryInfoKey(subkey)[0] + key_data.append(f'[{registry_root}\\{subkey_path}]') + # Enumerate the values of the current subkey and add them to the output list + for i in range(winreg.QueryInfoKey(subkey)[1]): + value_name, value_data, value_type = winreg.EnumValue(subkey, i) + key_data.append(f'"{value_name}"="{value_data}"') + # Add a blank line to the output list to separate subkeys + key_data.append('') + # Recursively export each subkey if recursive=True + for i in range(subkey_count): + subkey_name = winreg.EnumKey(subkey, i) + subkey_full_path = subkey_path + '\\' + subkey_name if subkey_path else subkey_name + if recursive: exporter(key, registry_root, subkey_full_path, key_data, recursive) + # Close the current subkey + winreg.CloseKey(subkey) + + key = key_map[registry_root] + + exporter(key, registry_root, registry_path, key_data, recursive) + open(export_path, 'w', encoding='utf-16').write('Windows Registry Editor Version 5.00\n\n' + '\n'.join(key_data)) + print(clr(f"\n > Successfully exported registry to \"{os.path.join(os.getcwd(), 'export.reg') if export_path == 'export.reg' else export_path}\"")) + + except: sys.exit(clr(err(sys.exc_info()), 2)) + +def clr(text: str, mode: int = 1, colour_one: str = white, colour_two: str = magenta) -> str: - elif mode == 2: - text = text.replace("[",f"{white}[{red}").replace("]",f"{white}]{red}") - for char in chars: text = text.replace(char, f"{white}{char}{red}") - for word in words_green: text = text.replace(word, f"{green}{word}{red}") + """ - # random | TRUE, FALSE will not be coloured! + this function colours special characters inside the 'chars' list + + ___________________________________________ - elif mode == 3 or mode == 4: - text = [char for char in text] - if mode == 3: colour_spl = True - else: colour_spl = False - for _ in range(len(text)): - char = text[_] - if char != ' ' and char != '\n': - if colour_spl: - if char in ( ['[',']'] + chars ): text[_] = white + char - else: text[_] = random.choice(colours) + Style.BRIGHT + char - else: - text[_] = random.choice(colours) + Style.BRIGHT + char - text = ''.join(text) + - mode: 1 | to display general text (default) + - text = white (default) / specified colour + - spl = magenta (default) / specified colour + + ___________________________________________ + + - mode: 2 | to display error messages + - text = red + - spl = white - else: print(str(f"\n {white}> {red}CLR ERROR{white}! - {red}Wrong mode {white}[{red}{mode}{white}]" + reset)); sys.exit(1) + ___________________________________________ - if mode != 3: - for _ in range(len(colours_to_replace)): - text = str(text).replace(colours_alt[_], colours_to_replace[_]) + - mode: 3 + - text = random + - spl = white - if mode == 1: return white + text + reset - elif mode == 2: return red + text + reset - elif mode == 3 or mode == 4: return text + reset + ___________________________________________ + + - mode: 4 | to display banners + - text & spl = random + + """ + + try: + if mode != 3: + for _ in range(len(colours_to_replace)): + text = text.replace(colours_to_replace[_], colours_alt[_]) + else: + for _ in range(len(colours_to_replace)): + text = text.replace(colours_to_replace[_], '') + + # default + + if mode == 1: + text = text.replace("[",f"{colour_two}[{colour_one}").replace("]",f"{colour_two}]{colour_one}") + for char in chars: text = text.replace(char, f"{colour_two}{char}{colour_one}") + for word in words_green: + replacement = green.join(list(word)) + text = text.replace(word, f"{green}{replacement}{colour_one}") + for word in words_red: + replacement = red.join(list(word)) + text = text.replace(word, f"{red}{replacement}{colour_one}") + + # for error messages + + elif mode == 2: + text = text.replace("[",f"{white}[{red}").replace("]",f"{white}]{red}") + for char in chars: text = text.replace(char, f"{white}{char}{red}") + for word in words_green: text = text.replace(word, f"{green}{word}{red}") + + # random | TRUE, FALSE will not be coloured! + + elif mode == 3 or mode == 4: + text = [char for char in text] + if mode == 3: colour_spl = True + else: colour_spl = False + for _ in range(len(text)): + char = text[_] + if char != ' ' and char != '\n': + if colour_spl: + if char in ( ['[',']'] + chars ): text[_] = white + char + else: text[_] = random.choice(colours) + Style.BRIGHT + char + else: + text[_] = random.choice(colours) + Style.BRIGHT + char + text = ''.join(text) + + else: raise ValueError(f"\n {white}> {red}Invalid Mode {white}[{red}{mode}{white}] | Valid Modes{white}: {red}1{white},{red}2{white},{red}3{white},{red}4" + reset) + + if mode != 3: + for _ in range(len(colours_to_replace)): + text = str(text).replace(colours_alt[_], colours_to_replace[_]) + + if mode == 1: return white + text + reset + elif mode == 2: return red + text + reset + elif mode == 3 or mode == 4: return text + reset + except: sys.exit(clr(err(sys.exc_info()), 2)) def align(text: str) -> str: """ center align banner / line ( supports both coloured and non-coloured ) - [NOTE] align supports: clr, does not support: fade + - [NOTE] align supports: clr, does not support: fade """ width = os.get_terminal_size().columns; aligned = text @@ -296,149 +387,148 @@ def fade(text: str, colour: str = "purple") -> str: """ credits to https://github.com/venaxyt/gratient & https://github.com/venaxyt/fade <3 - available_colours = [black,red,green,cyan,blue,purple,random,black-v,red-v,green-v,cyan-v,blue-v,purple-v,pink-v] + - available_colours = [black,red,green,cyan,blue,purple,random,black-v,red-v,green-v,cyan-v,blue-v,purple-v,pink-v] """ - colour = colour.lower() - if colour in available_colours: valid_colour = True - else: valid_colour = False - if not valid_colour: print(clr(f"\n > FADE ERROR! - Invalid colour: {colour} | Available colours: {', '.join(available_colours)}")); sys.exit(1) - - faded = "" - if len(text.splitlines()) > 1: multi_line = True - else: multi_line = False - - if colour == "black": - for line in text.splitlines(): - R = 0; G = 0; B = 0 - for char in line: - R += 3; G += 3; B += 3 - if R > 255 and G > 255 and B > 255: R = 255; G = 255; B = 255 - faded += f"\033[38;2;{R};{G};{B}m{char}\033[0m" - if multi_line: faded += "\n" + try: + colour = colour.lower() + if not colour in available_colours: raise ValueError(clr(f"\n > Invalid Colour: {colour} | Available Colours: {', '.join(available_colours)}",2)) - elif colour == "red": - for line in text.splitlines(): - G = 250 - for char in line: - G -= 5 - if G < 0: G = 0 - faded += f"\033[38;2;255;{G};0m{char}\033[0m" - if multi_line: faded += "\n" + faded = "" + if len(text.splitlines()) > 1: multi_line = True + else: multi_line = False + + if colour == "black": + for line in text.splitlines(): + R = 0; G = 0; B = 0 + for char in line: + R += 3; G += 3; B += 3 + if R > 255 and G > 255 and B > 255: R = 255; G = 255; B = 255 + faded += f"\033[38;2;{R};{G};{B}m{char}\033[0m" + if multi_line: faded += "\n" + + elif colour == "red": + for line in text.splitlines(): + G = 250 + for char in line: + G -= 5 + if G < 0: G = 0 + faded += f"\033[38;2;255;{G};0m{char}\033[0m" + if multi_line: faded += "\n" + + elif colour == "green": + for line in text.splitlines(): + R = 0 + for char in line: + if not R > 200: R += 3 + faded += f"\033[38;2;{R};255;0m{char}\033[0m" + if multi_line: faded += "\n" + + elif colour == "cyan": + for line in text.splitlines(): + B = 100 + for char in line: + B += 2 + if B > 255: B = 255 + faded += f"\033[38;2;0;255;{B}m{char}\033[0m" + if multi_line: faded += "\n" + + elif colour == "blue": + for line in text.splitlines(): + G = 0 + for char in line: + G += 3 + if G > 255: G = 255 + faded += f"\033[38;2;0;{G};255m{char}\033[0m" + if multi_line: faded += "\n" - elif colour == "green": - for line in text.splitlines(): + elif colour == "purple": + for line in text.splitlines(): + R = 35 + for char in line: + R += 3 + if R > 255: R = 255 + faded += f"\033[38;2;{R};0;220m{char}\033[0m" + if multi_line: faded += "\n" + + elif colour == "black-v": + R = 0; G = 0; B = 0 + for line in text.splitlines(): + faded += (f"\033[38;2;{R};{G};{B}m{line}\033[0m") + if not R == 255 and not G == 255 and not B == 255: + R += 20; G += 20; B += 20 + if R > 255 and G > 255 and B > 255: R = 255; G = 255; B = 255 + if multi_line: faded += "\n" + + elif colour == "red-v": + G = 250 + for line in text.splitlines(): + faded += f"\033[38;2;255;{G};0m{line}\033[0m" + if not G == 0: + G -= 25 + if G < 0: G = 0 + if multi_line:faded += "\n" + + elif colour == "green-v": R = 0 - for char in line: - if not R > 200: R += 3 - faded += f"\033[38;2;{R};255;0m{char}\033[0m" - if multi_line: faded += "\n" + for line in text.splitlines(): + faded += f"\033[38;2;{R};255;0m{line}\033[0m" + if not R > 200: R += 30 + if multi_line: faded += "\n" - elif colour == "cyan": - for line in text.splitlines(): + elif colour == "cyan-v": B = 100 - for char in line: - B += 2 - if B > 255: B = 255 - faded += f"\033[38;2;0;255;{B}m{char}\033[0m" - if multi_line: faded += "\n" - - elif colour == "blue": - for line in text.splitlines(): - G = 0 - for char in line: - G += 3 - if G > 255: G = 255 - faded += f"\033[38;2;0;{G};255m{char}\033[0m" - if multi_line: faded += "\n" - - elif colour == "purple": - for line in text.splitlines(): - R = 35 - for char in line: - R += 3 - if R > 255: R = 255 - faded += f"\033[38;2;{R};0;220m{char}\033[0m" - if multi_line: faded += "\n" - - elif colour == "black-v": - R = 0; G = 0; B = 0 - for line in text.splitlines(): - faded += (f"\033[38;2;{R};{G};{B}m{line}\033[0m") - if not R == 255 and not G == 255 and not B == 255: - R += 20; G += 20; B += 20 - if R > 255 and G > 255 and B > 255: R = 255; G = 255; B = 255 - if multi_line: faded += "\n" - - elif colour == "red-v": - G = 250 - for line in text.splitlines(): - faded += f"\033[38;2;255;{G};0m{line}\033[0m" - if not G == 0: - G -= 25 - if G < 0: G = 0 - if multi_line:faded += "\n" - - elif colour == "green-v": - R = 0 - for line in text.splitlines(): - faded += f"\033[38;2;{R};255;0m{line}\033[0m" - if not R > 200: R += 30 - if multi_line: faded += "\n" - - elif colour == "cyan-v": - B = 100 - for line in text.splitlines(): - faded += f"\033[38;2;0;255;{B}m{line}\033[0m" - if not B == 255: - B += 15 - if B > 255: B = 255 - if multi_line: faded += "\n" - - elif colour == "blue-v": - G = 10 - for line in text.splitlines(): - faded += f"\033[38;2;0;{G};255m{line}\033[0m" - if not G == 255: - G += 15 - if G > 255: G = 255 - if multi_line: faded += "\n" + for line in text.splitlines(): + faded += f"\033[38;2;0;255;{B}m{line}\033[0m" + if not B == 255: + B += 15 + if B > 255: B = 255 + if multi_line: faded += "\n" + + elif colour == "blue-v": + G = 10 + for line in text.splitlines(): + faded += f"\033[38;2;0;{G};255m{line}\033[0m" + if not G == 255: + G += 15 + if G > 255: G = 255 + if multi_line: faded += "\n" + + elif colour == "purple-v": + R = 40 + for line in text.splitlines(): + faded += f"\033[38;2;{R};0;220m{line}\033[0m" + if not R == 255: + R += 15 + if R > 255: R = 255 + if multi_line: faded += "\n" + + elif colour == "pink-v": + B = 255 + for line in text.splitlines(): + faded += f"\033[38;2;255;0;{B}m{line}\033[0m" + if not B == 0: + B -= 20 + if B < 0: B = 0 + if multi_line: faded += "\n" + + elif colour == "random": + for line in text.splitlines(): + for char in line: + R, G, B = random.randint(0,255), random.randint(0,255), random.randint(0,255) + faded += f"\033[38;2;{R};{G};{B}m{char}\033[0m" + if multi_line: faded += "\n" - elif colour == "purple-v": - R = 40 - for line in text.splitlines(): - faded += f"\033[38;2;{R};0;220m{line}\033[0m" - if not R == 255: - R += 15 - if R > 255: R = 255 - if multi_line: faded += "\n" + else: raise ValueError(clr(f"\n > FADE ERROR! - [{colour}] is not supported yet!",2)) - elif colour == "pink-v": - B = 255 - for line in text.splitlines(): - faded += f"\033[38;2;255;0;{B}m{line}\033[0m" - if not B == 0: - B -= 20 - if B < 0: B = 0 - if multi_line: faded += "\n" - - elif colour == "random": - for line in text.splitlines(): - for char in line: - R, G, B = random.randint(0,255), random.randint(0,255), random.randint(0,255) - faded += f"\033[38;2;{R};{G};{B}m{char}\033[0m" - if multi_line: faded += "\n" - - else: print(clr(f"\n > FADE ERROR! - [{colour}] is not supported yet!",2)); sys.exit(1) - - if multi_line: faded = faded[:-1] - return faded + if multi_line: faded = faded[:-1] + return faded + except: sys.exit(clr(err(sys.exc_info()), 2)) def get_duration(then, now = datetime.now(), interval = "default"): """ - Returns a duration as specified by variable interval - Functions, except totalDuration, returns [quotient, remainder] + Returns a duration as specified by the 'interval' variable """ duration = now - then # For build-in functions @@ -476,12 +566,18 @@ def totalDuration(): def err(exc_info) -> str: """ + Returns short traceback + + __________________________________________ + [EXAMPLE]: import sys + from dankware import err, clr try: value = 1/0 + except: print(clr(err(sys.exc_info()), 2)) """ @@ -490,20 +586,19 @@ def err(exc_info) -> str: stack_trace = [] for trace in trace_back: - stack_trace.append(" - File: {} | Line: {} | Function: {} | {}".format(trace[0].split('\\')[-1], trace[1], trace[2], trace[3])) - + # trace[0].split('\\')[-1] + stack_trace.append(" - File: {} | Line: {} | Function: {} | {}".format(trace[0], trace[1], trace[2], trace[3])) + report = " > Error Type: {}".format(ex_type.__name__) - if ex_value != '': report += "\n\n > Error Message: \n\n - {}".format(ex_value) - report += "\n\n > Error Stack Trace: \n\n{}".format('\n'.join(stack_trace)) + if ex_value: report += "\n > Error Message: \n - {}".format(ex_value) + report += "\n > Error Stack Trace: \n{}".format('\n'.join(stack_trace)) return report -# functions for windows executables [ dankware ] - def cls() -> None: """ - clear screen for multi-os + Clear screen for multi-os """ print(reset) @@ -513,7 +608,7 @@ def cls() -> None: def title(title: str) -> None: """ - changes title + Changes console window title """ if os.name == 'nt': os.system(f"title {title}") @@ -521,7 +616,7 @@ def title(title: str) -> None: def rm_line() -> None: """ - deletes previous line + Deletes previous line """ print("\033[A \033[A") @@ -529,16 +624,12 @@ def rm_line() -> None: def chdir(mode: str) -> str: """ - - running "os.chdir(os.path.dirname(__file__))" inside example.py will change its directory to the example.py file's location - running "os.chdir(os.path.dirname(sys.argv[0]))" inside example.exe will change its directory to the example.exe file's location (nuitka) - - for changing directory to exe's path as exe: exec(chdir("exe")) - for changing directory to script's path as script: exec(chdir("script")) - - [NOTE] When I build executables, the [ exec_mode = "script" ] is automatically replaced with [ exec_mode = "exe" ] inside the script - [NOTE] If you run "os.chdir(os.path.dirname(__file__))" as an executable, it will change its directory to its temp folder [ C:\\Users\\user\\AppData\\Local\\Temp\\dankware_PPID ] - + - running "os.chdir(os.path.dirname(__file__))" inside example.py will change its directory to the example.py file's location + - running "os.chdir(os.path.dirname(sys.argv[0]))" inside example.exe will change its directory to the example.exe file's location (nuitka) + - for changing directory to exe's path as exe: exec(chdir("exe")) + - for changing directory to script's path as script: exec(chdir("script")) + - [NOTE] When I build executables, the [ exec_mode = "script" ] is automatically replaced with [ exec_mode = "exe" ] inside the script + - [NOTE] If you run "os.chdir(os.path.dirname(__file__))" as an executable, it will change its directory to its temp folder [ C:\\Users\\user\\AppData\\Local\\Temp\\dankware_PPID ] """ if mode == "script": return "os.chdir(os.path.dirname(__file__))" # as .py @@ -547,9 +638,10 @@ def chdir(mode: str) -> str: def sys_open(item: str) -> None: """ - - opens the url on the default browser on windows / linux - - opens directory - - starts file + Can do the following: + - Open the url on the default browser on windows / linux + - Open directory + - Start file """ if os.name == 'nt': os.system(f'start {item}') @@ -558,7 +650,7 @@ def sys_open(item: str) -> None: def dankware_banner() -> None: """ - dankware banner printer with github url + Dankware banner printer with github url """ num_lines = os.get_terminal_size().lines diff --git a/run_tests.py b/run_tests.py new file mode 100644 index 0000000..ed65c7c --- /dev/null +++ b/run_tests.py @@ -0,0 +1,191 @@ +from dankware import * + +cls() +a = 0 +sum = 0 + +def main(): + + COUNTER = 0 + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + def example(): + global a + a += 1 + print(a) + time.sleep(1) + + multithread(example, 10) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + new_list = [1, 2, 3, 4, 5] + + def example(num): + global sum + sum += num + time.sleep(1) + + multithread(example, 10, new_list) # input_one: list + print(sum) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + list1 = [1, 2, 3, 4, 5] + list2 = [5, 4, 3, 2, 1] + + def example(num1, num2): + print(num1 + num2) + time.sleep(1) + + multithread(example, 10, list1, list2) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + new_list = [1, 2, 3, 4, 5] + + def example(num1, num2): + print(num1 * num2) + time.sleep(1) + + multithread(example, 10, new_list, 5, progress_bar=False) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + print(random_ip()) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + try: value = 1/0 + except: print(clr(err(sys.exc_info()), 2)) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + for url in github_downloads("EssentialsX/Essentials"): print(url) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + for url in github_file_selector("EssentialsX/Essentials", "remove", ['AntiBuild', 'Discord', 'GeoIP', 'Protect', 'XMPP']): print(url) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + print(clr("\n > Hey! Long time no see :)")) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + print(clr("\n > Hey! Long time no see :)", colour_one = magenta, colour_two = white)) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + print(clr("\n This is a string: True | This is an integer: False")) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + print(clr(f"\n > {magenta}Purple{white} thinks he's better than everyone else :(", colour_two=green)) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + print(clr("\n > Error in sector [7] redirecting... | INTEGRITY_CHECK_SUCCESS: TRUE",2)) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + print(clr("\n > Is this a randomly coloured string: TRUE | As you can see it does not colour True/False",3)) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + banner = ''' + + 888 888 + 888 888 s i r . d a n k ' s + 888 888 + .d88888 8888b. 88888b. 888 888 888 888 888 8888b. 888d888 .d88b. +d88" 888 "88b 888 "88b 888 .88P 888 888 888 "88b 888P" d8P Y8b +888 888 .d888888 888 888 888888K 888 888 888 .d888888 888 88888888 +Y88b 888 888 888 888 888 888 "88b Y88b 888 d88P 888 888 888 Y8b. + "Y88888 "Y888888 888 888 888 888 "Y8888888P" "Y888888 888 "Y8888 + +''' + print(clr(banner,4)) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + print(align(banner)) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + print(align(clr(banner,4))) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + banner = ''' + + 888 d8b 888 + v e n a x y t ' s 888 Y8P 888 + 888 888 + .d88b. 888d888 8888b. .d88888 888 .d88b. 88888b. 888888 +d88P"88b 888P" "88b d88" 888 888 d8P Y8b 888 "88b 888 +888 888 888 .d888888 888 888 888 88888888 888 888 888 +Y88b 888 888 888 888 Y88b 888 888 Y8b. 888 888 Y88b. + "Y88888 888 "Y888888 "Y88888 888 "Y8888 888 888 "Y888 + 888 +Y8b d88P + "Y88P" + + +''' + print(fade(banner, "black")) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + print(fade(banner, "black-v")) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + print(fade(banner, "red")) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + print(fade(banner, "red-v")) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + print(fade(banner, "green")) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + print(fade(banner, "green-v")) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + print(fade(banner, "cyan")) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + print(fade(banner, "cyan-v")) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + print(fade(banner, "blue")) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + print(fade(banner, "blue-v")) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + print(fade(banner, "purple")) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + print(fade(banner, "purple-v")) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + print(fade(banner, "pink-v")) + + COUNTER += 1; print(clr(f"\n___[{COUNTER}]__________________________________________________________________________________")) + + print(fade(banner, "random")) + +if __name__ == "__main__": main() diff --git a/setup.py b/setup.py index e328d99..b28add1 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="dankware", - version="3.0.1", + version="3.1", author="SirDank", author_email="SirDankenstein@protonmail.com", description="Python module with various features.",