Added base daun functionality
This commit is contained in:
10
modules/download.py
Normal file
10
modules/download.py
Normal file
@@ -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)
|
||||
41
modules/path.py
Normal file
41
modules/path.py
Normal file
@@ -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
|
||||
31
modules/process.py
Normal file
31
modules/process.py
Normal file
@@ -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()
|
||||
23
modules/screenshot.py
Normal file
23
modules/screenshot.py
Normal file
@@ -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
|
||||
18
modules/wallpaper.py
Normal file
18
modules/wallpaper.py
Normal file
@@ -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)
|
||||
11
modules/wallpaperengine.py
Normal file
11
modules/wallpaperengine.py
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user