From 3272a2b84effacc06c165b91d061ea0ca0abb9cc Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Thu, 22 Aug 2024 06:30:57 -0700 Subject: [PATCH] style: Apply linter formatting to testsr.py --- testsr.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/testsr.py b/testsr.py index 64c84f01d..ce22333a4 100644 --- a/testsr.py +++ b/testsr.py @@ -1,28 +1,30 @@ -import sys import re +import sys + def wordcount(text): """Count the number of words in the given text.""" return len(text.split()) + def process_markdown(filename): try: - with open(filename, 'r') as file: + with open(filename, "r") as file: content = file.read() # Split the content into sections based on '####' headers - sections = re.split(r'(?=####\s)', content) + sections = re.split(r"(?=####\s)", content) for section in sections: if section.strip(): # Ignore empty sections # Extract the header (if present) - header = section.split('\n')[0].strip() + header = section.split("\n")[0].strip() # Get the content (everything after the header) - content = '\n'.join(section.split('\n')[1:]).strip() - + content = "\n".join(section.split("\n")[1:]).strip() + # Count words count = wordcount(content) - + print(f"{header}: {count} words") except FileNotFoundError: @@ -30,6 +32,7 @@ def process_markdown(filename): except Exception as e: print(f"An error occurred: {e}") + if __name__ == "__main__": if len(sys.argv) != 2: print("Usage: python testsr.py ")