|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Script to improve wordings in HTML files to be more professional. |
| 4 | +Replaces terms like "dependents" with "Consumers" and related variations. |
| 5 | +""" |
| 6 | + |
| 7 | +import os |
| 8 | +import re |
| 9 | +from pathlib import Path |
| 10 | + |
| 11 | +# Define replacement patterns |
| 12 | +# Order matters - more specific patterns first |
| 13 | +REPLACEMENTS = [ |
| 14 | + # Specific phrases first |
| 15 | + (r'First-Level Dependencies', 'Primary Consumers'), |
| 16 | + (r'All Deeper Dependencies', 'Secondary Consumers'), |
| 17 | + (r'Dependent Libraries \(Latest Version:', 'Consumer Libraries (Latest Version:'), |
| 18 | + (r'Dependent Libraries', 'Consumer Libraries'), |
| 19 | + (r'No dependent libraries found', 'No consumer libraries found'), |
| 20 | + (r'with dependents', 'with consumers'), |
| 21 | + (r'for the latest version with dependents', 'for the latest version with consumers'), |
| 22 | + |
| 23 | + # Chart labels and titles |
| 24 | + (r'Dependency Count', 'Consumer Count'), |
| 25 | + |
| 26 | + # General word replacements (case-sensitive) |
| 27 | + (r'\bdependents\b', 'Consumers'), # whole word only |
| 28 | + (r'\bdependent\b', 'Consumer'), # whole word only |
| 29 | + |
| 30 | + # Note: We keep "dependencies" as is when it refers to actual dependencies, |
| 31 | + # but we've already replaced "Dependent Libraries" above |
| 32 | +] |
| 33 | + |
| 34 | +def process_file(file_path): |
| 35 | + """Process a single HTML file with all replacements.""" |
| 36 | + try: |
| 37 | + with open(file_path, 'r', encoding='utf-8') as f: |
| 38 | + content = f.read() |
| 39 | + |
| 40 | + original_content = content |
| 41 | + |
| 42 | + # Apply all replacements |
| 43 | + for pattern, replacement in REPLACEMENTS: |
| 44 | + content = re.sub(pattern, replacement, content) |
| 45 | + |
| 46 | + # Only write if content changed |
| 47 | + if content != original_content: |
| 48 | + with open(file_path, 'w', encoding='utf-8') as f: |
| 49 | + f.write(content) |
| 50 | + return True |
| 51 | + return False |
| 52 | + except Exception as e: |
| 53 | + print(f"Error processing {file_path}: {e}") |
| 54 | + return False |
| 55 | + |
| 56 | +def main(): |
| 57 | + """Main function to process all HTML files.""" |
| 58 | + # Get the script directory (project root) |
| 59 | + script_dir = Path(__file__).parent.absolute() |
| 60 | + |
| 61 | + # Find all HTML files |
| 62 | + html_files = [] |
| 63 | + |
| 64 | + # Root directory HTML files |
| 65 | + for html_file in script_dir.glob('*.html'): |
| 66 | + html_files.append(html_file) |
| 67 | + |
| 68 | + # HTML files in v1.90 directory |
| 69 | + v190_dir = script_dir / 'v1.90' |
| 70 | + if v190_dir.exists(): |
| 71 | + for html_file in v190_dir.glob('*.html'): |
| 72 | + html_files.append(html_file) |
| 73 | + |
| 74 | + # HTML files in v1.90/libraries directory |
| 75 | + libraries_dir = v190_dir / 'libraries' |
| 76 | + if libraries_dir.exists(): |
| 77 | + for html_file in libraries_dir.glob('*.html'): |
| 78 | + html_files.append(html_file) |
| 79 | + |
| 80 | + print(f"Found {len(html_files)} HTML files to process...") |
| 81 | + |
| 82 | + processed_count = 0 |
| 83 | + for html_file in html_files: |
| 84 | + if process_file(html_file): |
| 85 | + processed_count += 1 |
| 86 | + print(f"Updated: {html_file.relative_to(script_dir)}") |
| 87 | + |
| 88 | + print(f"\nProcessing complete!") |
| 89 | + print(f"Total files processed: {len(html_files)}") |
| 90 | + print(f"Files updated: {processed_count}") |
| 91 | + |
| 92 | +if __name__ == '__main__': |
| 93 | + main() |
0 commit comments