import os import re # pattern = re.compile(":::spoiler Gitlab sync([^:]*):::") # pattern = re.compile("[^:]*:::") def find_metadata(filename): with open(filename, "r") as file: print(f"File: {filename}") data = file.read() metadata = {} start_str = ":::spoiler Gitlab sync\n" end_str = "\n:::" start_i = data.find(start_str) if start_i >= 0: start_i += len(start_str) end_i = data.find(end_str, start_i + 1) file_data = data[start_i:end_i] for line in file_data.split("\n"): key_index = 2 value_index = line.find(": ") key = line[key_index:value_index] value = line[value_index + 2 :] metadata[key] = value print("Valid report") print(metadata) else: print("Not a valid report") return None return metadata