File size: 1,852 Bytes
7a0c684
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""

Emergency token cleanup script - removes all instances of HF token from all files

"""

import os
from pathlib import Path
import re

def find_all_files(start_path: str) -> list[Path]:
    """Find all files in the directory tree."""
    all_files = []
    for root, _, files in os.walk(start_path):
        if 'venv' in root or '__pycache__' in root or '.git' in root:
            continue
        for file in files:
            all_files.append(Path(os.path.join(root, file)))
    return all_files

def clean_token_from_file(file_path: Path, token: str) -> bool:
    """Remove token from a file."""
    try:
        with open(file_path, 'r', encoding='utf-8') as f:
            content = f.read()
        
        if token not in content:
            return False
            
        print(f"Cleaning {file_path}")
        
        # Replace the token
        content = content.replace(token, 'your_token_here')
        
        with open(file_path, 'w', encoding='utf-8') as f:
            f.write(content)
            
        return True
    except Exception as e:
        print(f"Error processing {file_path}: {e}")
        return False

def main():
    """Main cleanup function."""
    # Token to remove
    TOKEN = 'your_token_here'
    
    # Get project root
    root_dir = Path(__file__).parent.parent
    
    # Find all files
    all_files = find_all_files(root_dir)
    
    # Clean files
    cleaned = 0
    for file_path in all_files:
        if clean_token_from_file(file_path, TOKEN):
            cleaned += 1
    
    print(f"\nCleaned token from {cleaned} files")
    print("\nNext steps:")
    print("1. Update .env with your actual token")
    print("2. Make sure .env is in .gitignore")
    print("3. Commit the changes")

if __name__ == '__main__':
    main()