Created
September 11, 2023 14:30
-
-
Save yonasuriv/55523fdd53f855a08730b3dc08b75909 to your computer and use it in GitHub Desktop.
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
import os | |
# Read the data.txt file | |
with open("data.txt", "r") as file: | |
data = file.readlines() | |
# Initialize variables | |
functions = [] | |
current_function = {} | |
in_function = False | |
# Process the lines in data.txt | |
for line in data: | |
line = line.strip() | |
if line.startswith("Owner: "): | |
if in_function: | |
functions.append(current_function.copy()) | |
current_function = {} | |
in_function = True | |
if in_function: | |
parts = line.split(": ", 1) | |
if len(parts) == 2: | |
key, value = parts | |
current_function[key] = value | |
# Process the last function if one exists | |
if in_function: | |
functions.append(current_function.copy()) | |
# Display the number of functions found | |
print(f"Number of functions found: {len(functions)}") | |
# Ask the user for the word to exclude | |
exclude_word = input("Enter a word to exclude: ") | |
# Create a new text file excluding functions with the exclude_word in Path | |
new_data = [] | |
removed_count = 0 | |
for function in functions: | |
if "Path" in function and exclude_word not in function.get('Path', ''): | |
for key, value in function.items(): | |
new_data.append(f"{key}: {value}\n") | |
new_data.append("\n") | |
else: | |
removed_count += 1 | |
# Write the filtered data to a new file | |
with open("filtered_data.txt", "w") as file: | |
file.writelines(new_data) | |
print(f"Filtered data has been saved to 'filtered_data.txt'.") | |
print(f"Number of functions removed: {removed_count}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment