import os import shutil import zipfile import re from datetime import datetime def calculate_file_percentages(directory, file_counts): code_extensions = ['.html', '.css', '.js', '.py'] # Add more extensions if needed # Count the occurrences of each file extension for filename in os.listdir(directory): if os.path.isfile(os.path.join(directory, filename)): _, extension = os.path.splitext(filename) if extension: extension = extension.lower() # Convert extension to lowercase file_counts[extension] = file_counts.get(extension, 0) + 1 if extension in code_extensions: file_path = os.path.join(directory, filename) with open(file_path, 'r', encoding='utf-8') as file: content = file.read() if contains_code(content, extension): file_counts[extension] += 1 def contains_code(content, extension): if extension == '.html': css_pattern = r'\n') f.write('\n') f.write('
\n') f.write('Code Data:
\n') f.write(f'\n') for file in files: filename = os.path.basename(file) file_name_without_extension = os.path.splitext(filename)[0] f.write(f'{file_name_without_extension}
\n') f.write(f'\n') f.write(f'\n') f.write('\n') f.write('