-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- reworked structure - better linux support - several minor code improvements - new wallpaper (yay)
- Loading branch information
Showing
17 changed files
with
1,142 additions
and
1,138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import os | ||
import time | ||
from concurrent.futures import ThreadPoolExecutor | ||
|
||
if os.name == 'nt': | ||
import ctypes | ||
elif os.name == 'posix': | ||
import pwd # pylint: disable=import-error | ||
|
||
def is_admin() -> bool: | ||
|
||
""" | ||
Checks if executed with admin privileges and returns True if found else False | ||
""" | ||
|
||
if os.name == 'nt': | ||
try: return ctypes.windll.shell32.IsUserAnAdmin() | ||
except: return False | ||
elif os.name == 'posix': | ||
return pwd.getpwuid(os.getuid())[0] in ('root', '0') # pylint: disable=no-member | ||
else: | ||
raise ValueError(f"Unsupported Operating System: {os.name} | Supported: 'nt', 'posix'") | ||
|
||
''' | ||
def run_as_admin() -> None: | ||
""" | ||
Executes the script with admin privileges | ||
""" | ||
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1) | ||
#sys.exit(clr("\n > Exiting original un-elevated script...",2)) | ||
''' | ||
|
||
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
|
||
def hide_window() -> None: | ||
|
||
""" | ||
Hides console window | ||
Related to: | ||
- show_window() | ||
""" | ||
|
||
if os.name == 'nt': | ||
hWnd = ctypes.windll.kernel32.GetConsoleWindow() | ||
ctypes.windll.user32.ShowWindow(hWnd, 0) | ||
elif os.name == 'posix': | ||
os.system("xdotool getactivewindow windowminimize") | ||
else: | ||
raise ValueError(f"Unsupported Operating System: {os.name} | Supported: 'nt', 'posix'") | ||
|
||
def show_window() -> None: | ||
|
||
""" | ||
Shows console window | ||
Related to: | ||
- hide_window() | ||
""" | ||
|
||
if os.name == 'nt': | ||
hWnd = ctypes.windll.kernel32.GetConsoleWindow() | ||
ctypes.windll.user32.ShowWindow(hWnd, 1) | ||
elif os.name == 'posix': | ||
os.system("xdotool getactivewindow windowactivate") | ||
else: | ||
raise ValueError(f"Unsupported Operating System: {os.name} | Supported: 'nt', 'posix'") | ||
|
||
def hide_window_for(duration: int = 3) -> None: | ||
|
||
""" | ||
Hides console window for the given duration | ||
Related to: | ||
- hide_window() | ||
- show_window() | ||
""" | ||
|
||
def tmp(): | ||
hide_window() | ||
time.sleep(duration) | ||
show_window() | ||
|
||
ThreadPoolExecutor(1).submit(tmp) | ||
|
||
def minimise_window() -> None: | ||
|
||
""" | ||
Minimises console window | ||
Related to: | ||
- maximise_window() | ||
- restore_window() | ||
""" | ||
|
||
if os.name == 'nt': | ||
user32 = ctypes.WinDLL('user32') | ||
user32.ShowWindow(user32.GetForegroundWindow(), 6) | ||
elif os.name == 'posix': | ||
os.system("xdotool getactivewindow windowminimize") | ||
else: | ||
raise ValueError(f"Unsupported Operating System: {os.name} | Supported: 'nt', 'posix'") | ||
|
||
def maximise_window() -> None: | ||
|
||
""" | ||
Maximises console window | ||
Related to: | ||
- minimise_window() | ||
- restore_window() | ||
""" | ||
|
||
if os.name == 'nt': | ||
user32 = ctypes.WinDLL('user32') | ||
user32.ShowWindow(user32.GetForegroundWindow(), 3) | ||
elif os.name == 'posix': | ||
os.system("xdotool getactivewindow windowactivate windowmaximize") | ||
else: | ||
raise ValueError(f"Unsupported Operating System: {os.name} | Supported: 'nt', 'posix'") | ||
|
||
def restore_window() -> None: | ||
|
||
""" | ||
Restores console window to its original size | ||
Related to: | ||
- minimise_window() | ||
- maximise_window() | ||
""" | ||
|
||
if os.name == 'nt': | ||
user32 = ctypes.WinDLL('user32') | ||
user32.ShowWindow(user32.GetForegroundWindow(), 9) | ||
elif os.name == 'posix': | ||
os.system("xdotool getactivewindow windowactivate windowrestore") | ||
else: | ||
raise ValueError(f"Unsupported Operating System: {os.name} | Supported: 'nt', 'posix'") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
from datetime import datetime | ||
|
||
def get_duration(then: datetime, now: datetime = None, interval: str = "default") -> int | str: | ||
|
||
""" | ||
Returns a duration as specified by the 'interval' variable | ||
__________________________________________________________ | ||
valid intervals: | ||
- year -> int | ||
- month -> int | ||
- week -> int | ||
- day -> int | ||
- hour -> int | ||
- minute -> int | ||
- second -> int | ||
- dynamic -> str | ||
- dynamic-mini -> str | ||
- default -> str | ||
- default-mini -> str | ||
""" | ||
|
||
if not now: now = datetime.now() | ||
interval = interval.lower() | ||
duration = now - then | ||
|
||
if "year" in interval: return int(duration.days / 365) | ||
if "month" in interval: return int(duration.days / 30) | ||
if "week" in interval: return int(duration.days / 7) | ||
if "day" in interval: return duration.days | ||
if "hour" in interval: return int(duration.total_seconds() / 3600) | ||
if "minute" in interval: return int(duration.total_seconds() / 60) | ||
if "second" in interval: return int(duration.total_seconds()) | ||
if "dynamic" in interval: | ||
|
||
mini = bool(interval == "dynamic-mini") | ||
seconds = duration.total_seconds() | ||
|
||
if seconds < 60: | ||
if mini: return f"{int(seconds)}s" | ||
return f"{int(seconds)} second{'s' if seconds > 1 else ''}" | ||
|
||
if seconds < 3600: | ||
minutes = int(seconds / 60) | ||
if mini: return f"{minutes}m" | ||
return f"{minutes} minute{'s' if minutes > 1 else ''}" | ||
|
||
if seconds < 86400: | ||
hours = int(seconds / 3600) | ||
if mini: return f"{hours}h" | ||
return f"{hours} hour{'s' if hours > 1 else ''}" | ||
|
||
if seconds < 604800: | ||
days = int(seconds / 86400) | ||
if mini: return f"{days}d" | ||
return f"{days} day{'s' if days > 1 else ''}" | ||
|
||
if seconds < 2592000: | ||
weeks = int(seconds / 604800) | ||
if mini: return f"{weeks}w" | ||
return f"{weeks} week{'s' if weeks > 1 else ''}" | ||
|
||
if seconds < 31536000: | ||
months = int(seconds / 2592000) | ||
if mini: return f"{months}m" | ||
return f"{months} month{'s' if months > 1 else ''}" | ||
|
||
years = int(seconds / 31536000) | ||
if mini: return f"{years}y" | ||
return f"{years} year{'s' if years > 1 else ''}" | ||
|
||
if "default" in interval: | ||
|
||
seconds = duration.total_seconds() | ||
years = int(seconds / 31536000) | ||
months = int((seconds % 31536000) / 2592000) | ||
weeks = int((seconds % 2592000) / 604800) | ||
days = int((seconds % 604800) / 86400) | ||
hours = int((seconds % 86400) / 3600) | ||
minutes = int((seconds % 3600) / 60) | ||
seconds = int(seconds % 60) | ||
|
||
parts = [] | ||
if interval == "default": | ||
if years: parts.append(f"{years} year{'s' if years > 1 else ''}") | ||
if months: parts.append(f"{months} month{'s' if months > 1 else ''}") | ||
if weeks: parts.append(f"{weeks} week{'s' if weeks > 1 else ''}") | ||
if days: parts.append(f"{days} day{'s' if days > 1 else ''}") | ||
if hours: parts.append(f"{hours} hour{'s' if hours > 1 else ''}") | ||
if minutes: parts.append(f"{minutes} minute{'s' if minutes > 1 else ''}") | ||
if seconds: parts.append(f"{seconds} second{'s' if seconds > 1 else ''}") | ||
|
||
elif interval == "default-mini": | ||
if years: parts.append(f"{years}y") | ||
if months: parts.append(f"{months}mo") | ||
if weeks: parts.append(f"{weeks}w") | ||
if days: parts.append(f"{days}d") | ||
if hours: parts.append(f"{hours}h") | ||
if minutes: parts.append(f"{minutes}m") | ||
if seconds: parts.append(f"{seconds}s") | ||
|
||
return ", ".join(parts) | ||
|
||
raise ValueError(f"Invalid Interval: {interval} | Valid Intervals: year, month, week, day, hour, minute, second, dynamic, dynamic-mini, default, default-mini") |
Oops, something went wrong.