-
Notifications
You must be signed in to change notification settings - Fork 2
/
remove_api_token.py
41 lines (31 loc) · 1.19 KB
/
remove_api_token.py
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
import os
def replace_placeholder(file_path, placeholder, new_value):
"""
Replace all occurrences of a new value in a file with a placeholder.
"""
try:
with open(file_path, 'r') as file:
content = file.read()
updated_content = content.replace(new_value, placeholder)
with open(file_path, 'w') as file:
file.write(updated_content)
print(f"Replaced {new_value} with {placeholder} in {file_path}")
except Exception as e:
print(f"Failed to update {file_path}: {e}")
def main():
files_and_placeholders = [
("autogpt/.env", "GLOBAL-API-KEY-PLACEHOLDER"),
("run.sh", "GLOBAL-API-KEY-PLACEHOLDER"),
]
# Read the replacement value from token.txt
try:
with open("openai_token.txt", "r") as token_file:
replacement_value = token_file.read().strip()
except FileNotFoundError:
print("Error: token.txt not found. Please run the first script to generate it.")
return
# Restore placeholders in files
for file_path, placeholder in files_and_placeholders:
replace_placeholder(file_path, placeholder, replacement_value)
if __name__ == "__main__":
main()