From acb5925e1379f982747f5faead87c3dd6799fd81 Mon Sep 17 00:00:00 2001 From: Justin Oros Date: Mon, 18 Nov 2024 10:42:17 -0700 Subject: [PATCH] Update dnet-stats.py Rearranged arguments for a more logical use case. --- dnet-stats.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/dnet-stats.py b/dnet-stats.py index 2eb1ce7..d96ab04 100644 --- a/dnet-stats.py +++ b/dnet-stats.py @@ -1,6 +1,6 @@ #!/usr/bin/python3 -# Description: A command-line interface to stats.distributed.net -# Usage: python3 dnet-stats.py -User -Project +# Description: A command-line interface to https://stats.distributed.net +# Usage: python3 dnet-stats.py -Project -User # Author: Justin Oros # Source: https://github.com/JustinOros # Dependencies: pip install requests beautifulsoup4 @@ -60,11 +60,11 @@ def helpMenu(): print( Text.Bold + Text.Green + '\nHelp Menu:\n' + Text.Bold + Text.Green + '\nUsage: ' + - Text.Reset + Text.Green + 'dnet-stats.py -User -Project \n' + + Text.Reset + Text.Green + 'dnet-stats.py -Project -User \n' + Text.Bold + Text.Green + '\nProjects: ' + Text.Reset + Text.Green + 'RC5-56, RC5-64, RC5-72, OGR-24, OGR-25, OGR-26, OGR-27, OGR-28\n' + Text.Bold + Text.Green + '\nExample: ' + - Text.Reset + Text.Green + 'python3 dnet-stats.py -User bluecat9@penguinized.net -Project RC5-72\n' + Text.Reset + Text.Reset + Text.Green + 'python3 dnet-stats.py -Project RC5-72 -User bluecat9@penguinized.net\n' + Text.Reset ) exit() @@ -74,17 +74,17 @@ project = None # Check if the arguments are provided and valid for i in range(1, len(sys.argv)): - if sys.argv[i] == "-User" and i + 1 < len(sys.argv): - user = sys.argv[i + 1] if sys.argv[i] == "-Project" and i + 1 < len(sys.argv): project = sys.argv[i + 1].upper() + if sys.argv[i] == "-User" and i + 1 < len(sys.argv): + user = sys.argv[i + 1] -# Check if both user and project are provided +# Ensure both project and user are present if not user or not project: - print(Text.Bold + Text.Red + "Error: Missing required arguments. Use -User and -Project." + Text.Reset) + print(Text.Bold + Text.Red + "Error: Missing required arguments. Use -Project and -User." + Text.Reset) helpMenu() -# Ensure the project argument is a valid project +# Ensure the project is valid if project not in validProjects: print(Text.Bold + Text.Red + f"Error: {project} is not a valid project.\n" + Text.Reset) helpMenu() @@ -98,7 +98,7 @@ data = {'project_id': projectId, 'st': user} # Perform a POST request to fetch the response response = requests.post(searchUrl, data=data) -if response: # If we received a response +if response: # Proceed if we received a response soup = BeautifulSoup(response.text, 'lxml') # Load the response into BeautifulSoup summary = soup.find('td', class_='htitle').text.lstrip() # Find summary