From e5cfbe4dd090fe43bc9e628e0a4530c4a0fa0d44 Mon Sep 17 00:00:00 2001 From: Whispering Wind <151555003+ReturnFI@users.noreply.github.com> Date: Mon, 15 Jul 2024 14:14:01 +0330 Subject: [PATCH] Add Colors --- modify.py | 53 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/modify.py b/modify.py index 6b8070f..5e039e7 100644 --- a/modify.py +++ b/modify.py @@ -6,6 +6,13 @@ from datetime import datetime users_file_path = '/etc/hysteria/users/users.json' +def colors(): + green='\033[0;32m' + cyan='\033[0;36m' + red='\033[0;31m' + NC='\033[0m' # No Color + return green, cyan, red, NC + def load_users(): with open(users_file_path, 'r') as file: return json.load(file) @@ -19,41 +26,49 @@ def generate_password(): return result.stdout.strip() def list_users(users): + green, cyan, red, NC = colors() + print(f"{green}List of Users{NC}\n") for i, user in enumerate(users.keys(), start=1): - print(f"{i}. {user}") + print(f"{cyan}{i}. {user}{NC}") def edit_user(users): + green, cyan, red, NC = colors() list_users(users) try: - choice = int(input("Enter the number of the user to edit: ")) + choice = int(input(f"{green}Enter the number of the user to edit:{NC} ")) username = list(users.keys())[choice - 1] except (ValueError, IndexError): - print("Invalid choice.") + print(f"{green}Invalid choice.{NC}") return - print(f"Editing user: {username}") + print(f"{green}Editing user: {cyan}{username}{NC}") change_password = input(f"Change password? (current: {users[username]['password']}) [y/N]: ").lower() == 'y' if change_password: new_password = generate_password() users[username]['password'] = new_password - print(f"New password: {new_password}") + print(f"{green}New password: {cyan}{new_password}{NC}") while True: - max_download_gb = input(f"Enter new max download bytes in GB (current: {users[username]['max_download_bytes'] // (1024 ** 3)} GB): ") - if max_download_gb.isdigit(): + current_max_download_gb = users[username]['max_download_bytes'] // (1024 ** 3) + max_download_gb = input(f"Enter new max download bytes in GB (current: {current_max_download_gb} GB, press Enter to keep current): ") + if max_download_gb.strip() == '': + break + elif max_download_gb.isdigit(): users[username]['max_download_bytes'] = int(max_download_gb) * (1024 ** 3) break else: - print("Invalid input. Please enter a valid number.") + print(f"{red}Invalid input. Please enter a valid number or press Enter to keep current.{NC}") while True: - expiration_days = input(f"Enter new expiration days (current: {users[username]['expiration_days']}): ") - if expiration_days.isdigit(): + expiration_days = input(f"Enter new expiration days (current: {users[username]['expiration_days']}, press Enter to keep current): ") + if expiration_days.strip() == '': + break + elif expiration_days.isdigit(): users[username]['expiration_days'] = int(expiration_days) break else: - print("Invalid input. Please enter a valid number.") + print(f"{red}Invalid input. Please enter a valid number or press Enter to keep current.{NC}") blocked = input(f"Blocked? (current: {users[username]['blocked']}) [true/false]: ").lower() if blocked: @@ -64,24 +79,28 @@ def edit_user(users): users[username]['account_creation_date'] = datetime.today().strftime('%Y-%m-%d') def main(): + green, cyan, red, NC = colors() + if not os.path.exists(users_file_path): - print(f"File {users_file_path} does not exist.") + print(f"{red}File {users_file_path} does not exist.{NC}") return users = load_users() while True: - print("1. Edit user") - print("2. Exit") - choice = input("Enter your choice: ") + print(f"{green}1. Edit user{NC}") + print(f"{red}2. Exit{NC}") + choice = input(f"{NC}Enter your choice: {NC}") if choice == "1": edit_user(users) save_users(users) elif choice == "2": - return + print(f"{red}Exiting...{NC}") + break else: - print("Invalid choice. Please try again.") + print(f"{NC}Invalid choice. Please try again.{NC}") if __name__ == "__main__": main() +