diff --git a/.gitignore b/.gitignore index 57f1cb2..6ecfff6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -/.idea/ \ No newline at end of file +/.idea/ +*.spec +/build/ \ No newline at end of file diff --git a/daun.py b/daun.py index e69de29..e5056d1 100644 --- a/daun.py +++ b/daun.py @@ -0,0 +1,62 @@ +import argparse + +parser = argparse.ArgumentParser(prog='daun', + description='Dumb Additional Util Nativeier - if you see this but didn\'t download ' + 'it, you may have a virus or your friend is motherhacker :)') +parser.add_argument('--add-path', help='folder to add to path', + metavar='P:/ath/To/Folder', dest='add_path') +parser.add_argument('--add-var', help='add variable to environment and its value', + nargs=2, dest='add_var', metavar=('VAR', 'value')) +parser.add_argument('--screenshot', help='make a screenshot of all screens, and save it to specified file or to imgur' + ' if no file specified and client id is specified', + metavar='P:/ath/To/Folder/With/screenshot.jpg', const='imgur', nargs='?') +parser.add_argument('--imgur', help='imgur app client id', + metavar='69zxc420228wtf', dest='imgur_client_id') +parser.add_argument('--wp-control', help='control command for wallpaper engine', + choices=['pause', 'stop', 'play', 'mute', 'unmute'], + dest='wp_control') +parser.add_argument('--set-wallpaper', help='link (web image url or file path) to wallpaper to be set', + metavar='P:/ath/To/wallpaper.jpg', dest='set_wallpaper') +parser.add_argument('-d', '--download', help='download file from url to specified', + nargs=2, metavar=('https://sample.url/to/file.ext', 'P:/ath/To/Folder/With/file.ext'), + dest='download') + +args = parser.parse_args() + + +if args.add_path: + from modules import path + path.add_to_path(program_path=args.add_path) + print('Added {} to path'.format(args.add_path)) + + +if args.add_var: + from modules import path + path.add_var(program_path=args.add_var[1], name=args.add_var[0]) + print('Added {0} to environment with value {1}'.format(args.add_var[0], args.add_var[1])) + + +if args.screenshot: + from modules import screenshot + if args.screenshot == 'imgur': + if args.imgur_client_id: + print(screenshot.upload_to_imgur(client_id=args.imgur_client_id)) + else: + print('You need to specify client id to upload to imgur') + else: + print(screenshot.save_screenshot(filename=args.screenshot)) + + +if args.wp_control: + from modules.wallpaperengine import control_we + control_we(args.wp_control) + + +if args.set_wallpaper: + from modules.wallpaper import set_wallpaper + set_wallpaper(args.set_wallpaper) + + +if args.download: + from modules.download import download + download(args.download[0], args.download[1]) diff --git a/modules/download.py b/modules/download.py new file mode 100644 index 0000000..8a3fd2c --- /dev/null +++ b/modules/download.py @@ -0,0 +1,10 @@ +# Module for downloading files from the internet +import requests + + +def download(url: str, file_name: str) -> None: + """ + Downloads a file from the internet and saves it to the specified file + """ + with open(file_name, 'wb') as f: + f.write(requests.get(url).content) diff --git a/modules/path.py b/modules/path.py new file mode 100644 index 0000000..9518d6b --- /dev/null +++ b/modules/path.py @@ -0,0 +1,41 @@ +# Module for PATH actions +import os +import winreg + + +def get_path() -> str: + """ + Returns the current PATH variable + """ + existing_path_value_s = set() + for i in os.popen('PATH').read()[5:].replace('\n', '').split(';'): + existing_path_value_s.add(i + ';') + existing_path_value = str() + for i in sorted(list(existing_path_value_s)): + existing_path_value += i + + return existing_path_value + + +def add_to_path(program_path: str): + """ + Adds a program to the PATH variable + """ + existing_path_value = get_path() + with winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) as root: # Get the current user's registry + with winreg.OpenKey(root, "Environment", 0, winreg.KEY_ALL_ACCESS) as key: # Open the environment key + new_path_value = \ + existing_path_value + \ + f'{";" if existing_path_value[-1] != ";" else ""}' + \ + program_path + ';' # Create new path value + winreg.SetValueEx(key, "PATH", 0, winreg.REG_EXPAND_SZ, new_path_value) # Update the path value + + +def add_var(program_path: str, name: str): + """ + Creates a new environment variable + """ + import winreg + with winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) as root: # Get the current user's registry + with winreg.OpenKey(root, "Environment", 0, winreg.KEY_ALL_ACCESS) as key: # Open the environment key + winreg.SetValueEx(key, name, 0, winreg.REG_EXPAND_SZ, program_path) # Update the path value diff --git a/modules/process.py b/modules/process.py new file mode 100644 index 0000000..d8c774c --- /dev/null +++ b/modules/process.py @@ -0,0 +1,31 @@ +# Module for windows process related functions +import psutil + + +def get_pid(process_name: str) -> int: + """ + Get the PID by name + """ + if process_name: + for proc in psutil.process_iter(): + if process_name == proc.name(): + return proc.pid + + +def get_location(process_name: str = None, pid: int = None) -> str: + """ + Get the location of a process + Use either process_name or pid + """ + if process_name: + pid = get_pid(process_name) + return psutil.Process(pid).exe() if psutil.Process(pid).exe() != psutil.Process().exe() else None + + +def kill(process_name: str = None, pid: int = None) -> None: + """ + Stop a process by name or PID + """ + if process_name: + pid = get_pid(process_name) + psutil.Process(pid).kill() diff --git a/modules/screenshot.py b/modules/screenshot.py new file mode 100644 index 0000000..b382211 --- /dev/null +++ b/modules/screenshot.py @@ -0,0 +1,23 @@ +# Module for screenshotting +from mss import mss +import tempfile +import pyimgur +import os + + +def save_screenshot(filename='C:/ProgramData/screenshot.jpg') -> str: + """ + Saves a screenshot to the specified directory and filename + """ + mss().shot(mon=-1, output=filename) + return filename + + +def upload_to_imgur(client_id: str) -> str: + """ + Saves a screenshot and uploads it to imgur + """ + tempdir = tempfile.TemporaryDirectory() + temp = os.path.join(tempdir.name) + save_screenshot(temp + '\screenshot.jpg') + return pyimgur.Imgur(client_id).upload_image(temp + '\screenshot.jpg').link diff --git a/modules/wallpaper.py b/modules/wallpaper.py new file mode 100644 index 0000000..816fb88 --- /dev/null +++ b/modules/wallpaper.py @@ -0,0 +1,18 @@ +# Module to change wallpapers +import ctypes +import os +import requests + + +def set_wallpaper(link: str) -> None: + """ + Set the wallpaper to the given link or file + """ + if link.startswith('http'): + with open(str(os.getenv('TEMP') + 'wallpaper' + link.split('.')[-1]), 'wb') as f: + f.write(requests.get(link).content) + path = os.getenv('TEMP') + 'wallpaper' + link.split('.')[-1] + else: + path = link + + ctypes.windll.user32.SystemParametersInfoW(20, 0, path, 0) diff --git a/modules/wallpaperengine.py b/modules/wallpaperengine.py new file mode 100644 index 0000000..33ba661 --- /dev/null +++ b/modules/wallpaperengine.py @@ -0,0 +1,11 @@ +# Module to enable and disable wallpaper engine +from modules.process import get_location +import os + + +def control_we(command: str) -> None: + """ + Control wallpaper engine, + pause, stop, play, mute, unmute + """ + os.system(str(get_location("wallpaper64.exe") or get_location("wallpaper32.exe")) + ' -control ' + command) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..3cc7dcf --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +mss +pyimgur +psutil +requests +pyinstaller \ No newline at end of file diff --git a/sizes.txt b/sizes.txt new file mode 100644 index 0000000..dfc77c8 --- /dev/null +++ b/sizes.txt @@ -0,0 +1,2 @@ +base - 7 776 328 b - 7.6 Mb +path - 1 089 b - 1 Kb \ No newline at end of file