diff --git a/pyproject.toml b/pyproject.toml index ad741e9..60eb0df 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -149,7 +149,7 @@ ignore-patterns = [".*\\.pyi$"] [tool.pylint.messages_control] # Enable all checks by disabling disable enable = "all" -# Minimal disabled checks - only truly problematic ones +# Minimal disabled checks - pylint internal/meta messages only disable = [ "raw-checker-failed", "bad-inline-option", @@ -159,8 +159,6 @@ disable = [ "useless-suppression", "deprecated-pragma", "use-symbolic-message-instead", - "too-few-public-methods", # Often false positive for data classes - "invalid-name", # Existing camelCase folder names (downloadCats, etc.) ] [tool.pylint.format] diff --git a/python_pkg/download_cats/generate_cats.py b/python_pkg/download_cats/generate_cats.py index dd10693..ad34227 100644 --- a/python_pkg/download_cats/generate_cats.py +++ b/python_pkg/download_cats/generate_cats.py @@ -40,16 +40,22 @@ def _download_single_image(image_url: str) -> None: _logger.exception("Failed to download %s", image_url) -requests_send = 0 -while requests_send < MAX_REQUESTS: - res = requests.get( - "https://api.thecatapi.com/v1/images/search?limit=100&api_key=", - timeout=REQUEST_TIMEOUT, - ) - requests_send += 1 - response = json.loads(res.text) - urls = [cat.get("url") for cat in response] +def main() -> None: + """Download cat images from TheCatAPI.""" + requests_sent = 0 + while requests_sent < MAX_REQUESTS: + res = requests.get( + "https://api.thecatapi.com/v1/images/search?limit=100&api_key=", + timeout=REQUEST_TIMEOUT, + ) + requests_sent += 1 + response = json.loads(res.text) + urls = [cat.get("url") for cat in response] - Path("./CATS2").mkdir(parents=True, exist_ok=True) - for url in urls: - _download_single_image(url) + Path("./CATS2").mkdir(parents=True, exist_ok=True) + for url in urls: + _download_single_image(url) + + +if __name__ == "__main__": + main() diff --git a/python_pkg/random_jpg/generate_jpeg.py b/python_pkg/random_jpg/generate_jpeg.py index c0a7d1b..29b6c15 100644 --- a/python_pkg/random_jpg/generate_jpeg.py +++ b/python_pkg/random_jpg/generate_jpeg.py @@ -86,7 +86,8 @@ def _save_image( return str(unique_output_path) -if __name__ == "__main__": +def main() -> None: + """Generate bloated JPEG images from command line arguments.""" parser = argparse.ArgumentParser( description="Generate bloated JPEG images with random colors." ) @@ -165,5 +166,9 @@ if __name__ == "__main__": quality=args.quality, ) for i in range(1, args.num_images + 1): - output_path = generate_bloated_jpeg(config, i, folder) - _logger.info("Image %s saved to %s", i, Path(output_path).resolve()) + result_path = generate_bloated_jpeg(config, i, folder) + _logger.info("Image %s saved to %s", i, Path(result_path).resolve()) + + +if __name__ == "__main__": + main() diff --git a/python_pkg/randomize_numbers/random_digits.py b/python_pkg/randomize_numbers/random_digits.py index fc9c35e..2649028 100644 --- a/python_pkg/randomize_numbers/random_digits.py +++ b/python_pkg/randomize_numbers/random_digits.py @@ -70,7 +70,9 @@ def _parse_single_number(num_str: str) -> tuple[float, int] | None: MIN_ARGS = 2 -if __name__ == "__main__": + +def main() -> None: + """Run the number randomizer from command line arguments.""" if len(sys.argv) < MIN_ARGS: _logger.info( "Usage: python random_digits.py ... " @@ -78,27 +80,27 @@ if __name__ == "__main__": ) sys.exit(1) - input_string = " ".join(sys.argv[1:]) - numbers, decimal_counts = parse_input(input_string) + args_string = " ".join(sys.argv[1:]) + numbers, decimal_counts = parse_input(args_string) if not numbers: _logger.error("No valid numbers provided.") sys.exit(1) - min_percentage = DEFAULT_MIN_PERCENTAGE - max_percentage = DEFAULT_MAX_PERCENTAGE + min_pct = DEFAULT_MIN_PERCENTAGE + max_pct = DEFAULT_MAX_PERCENTAGE try: if len(sys.argv) > len(numbers) + 1: with contextlib.suppress(ValueError): - min_percentage = float(sys.argv[len(numbers) + 1]) + min_pct = float(sys.argv[len(numbers) + 1]) if len(sys.argv) > len(numbers) + 2: with contextlib.suppress(ValueError): - max_percentage = float(sys.argv[len(numbers) + 2]) + max_pct = float(sys.argv[len(numbers) + 2]) - randomized_numbers = randomize_numbers(numbers, min_percentage, max_percentage) + randomized = randomize_numbers(numbers, min_pct, max_pct) formatted_numbers = [] - for i, num in enumerate(randomized_numbers): + for i, num in enumerate(randomized): format_str = f".{decimal_counts[i]}f" formatted_numbers.append(float(format(num, format_str))) @@ -108,3 +110,7 @@ if __name__ == "__main__": _logger.exception("Error processing numbers") _logger.exception("Please provide valid numbers and percentages.") sys.exit(1) + + +if __name__ == "__main__": + main() diff --git a/python_pkg/scrape_website/scrape_comics.py b/python_pkg/scrape_website/scrape_comics.py index ab4edd2..db779c4 100644 --- a/python_pkg/scrape_website/scrape_comics.py +++ b/python_pkg/scrape_website/scrape_comics.py @@ -18,24 +18,8 @@ _logger = logging.getLogger(__name__) REQUEST_TIMEOUT = 30 # seconds -# Initialize argument parser to accept the website URL as an argument -parser = argparse.ArgumentParser(description="Download images from a comic website.") -parser.add_argument( - "url", type=str, help="The URL of the website to start downloading images from" -) -args = parser.parse_args() -# Initialize WebDriver (Use the appropriate driver for your browser) -driver = webdriver.Chrome() - -# Open the website from the passed argument -url = args.url -_logger.info("Opening the website: %s", url) -driver.get(url) - - -# A function to download images by URL -def download_image(image_url: str) -> bool: +def _download_image(image_url: str) -> bool: """Download an image from a URL and save it locally.""" # Extract image name from URL image_name = Path(urlparse(image_url).path).name @@ -53,37 +37,58 @@ def download_image(image_url: str) -> bool: return True -# No need to define a specific number of images now -count = 1 +def main() -> None: + """Download comic images from a website using Selenium.""" + # Initialize argument parser to accept the website URL as an argument + parser = argparse.ArgumentParser( + description="Download images from a comic website." + ) + parser.add_argument( + "url", type=str, help="The URL of the website to start downloading images from" + ) + args = parser.parse_args() -while True: - _logger.info("Processing image %s...", count) + # Initialize WebDriver (Use the appropriate driver for your browser) + driver = webdriver.Chrome() - # Find the image element by its ID - image_element = driver.find_element(By.ID, "cc-comic") + # Open the website from the passed argument + _logger.info("Opening the website: %s", args.url) + driver.get(args.url) - # Get the image URL from the 'src' attribute - current_image_url = image_element.get_attribute("src") - _logger.info("Found image URL: %s", current_image_url) + image_count = 1 - # Download the image if it doesn't already exist - if download_image(current_image_url): - count += 1 # Increment count only if the image was downloaded + while True: + _logger.info("Processing image %s...", image_count) - # Try to find the 'Next' button by its class - try: - _logger.info("Clicking the 'Next' button to load the next image...") - next_button = driver.find_element(By.CSS_SELECTOR, "a.cc-next") + # Find the image element by its ID + image_element = driver.find_element(By.ID, "cc-comic") - # Navigate to the URL in the 'href' of the next button - next_button_url = next_button.get_attribute("href") - driver.get(next_button_url) + # Get the image URL from the 'src' attribute + current_image_url = image_element.get_attribute("src") + _logger.info("Found image URL: %s", current_image_url) - except NoSuchElementException: - # If the 'Next' button is not found, it means we've reached the last image - _logger.info("No 'Next' button found. Reached the end of images.") - break + # Download the image if it doesn't already exist + if _download_image(current_image_url): + image_count += 1 # Increment count only if the image was downloaded -# Close the browser -_logger.info("All images processed, closing the browser.") -driver.quit() + # Try to find the 'Next' button by its class + try: + _logger.info("Clicking the 'Next' button to load the next image...") + next_button = driver.find_element(By.CSS_SELECTOR, "a.cc-next") + + # Navigate to the URL in the 'href' of the next button + next_button_url = next_button.get_attribute("href") + driver.get(next_button_url) + + except NoSuchElementException: + # If the 'Next' button is not found, it means we've reached the last image + _logger.info("No 'Next' button found. Reached the end of images.") + break + + # Close the browser + _logger.info("All images processed, closing the browser.") + driver.quit() + + +if __name__ == "__main__": + main()