-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_key_manager.py
More file actions
69 lines (60 loc) · 1.97 KB
/
api_key_manager.py
File metadata and controls
69 lines (60 loc) · 1.97 KB
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
67
68
69
import keyring
SERVICE_NAME = "FS25_Translator"
KEY_NAME = "deepl_api_key"
def check_key():
"""Check if API key exists"""
try:
key = keyring.get_password(SERVICE_NAME, KEY_NAME)
if key:
print(f"✅ API key found: {key[:10]}..." if len(key) > 10 else key)
return True
else:
print("❌ No API key stored")
return False
except Exception as e:
print(f"Error checking key: {e}")
return False
def delete_key():
"""Safely delete API key"""
try:
# First check if it exists
if keyring.get_password(SERVICE_NAME, KEY_NAME):
keyring.delete_password(SERVICE_NAME, KEY_NAME)
print("✅ API key removed successfully")
else:
print("ℹ️ No API key to remove")
except keyring.errors.PasswordDeleteError:
print("ℹ️ No API key was stored")
except Exception as e:
print(f"❌ Error: {e}")
def set_key():
"""Set a test API key"""
test_key = input("Enter API key (or 'test' for test key): ")
if test_key.lower() == 'test':
test_key = "test-api-key-12345"
try:
keyring.set_password(SERVICE_NAME, KEY_NAME, test_key)
print(f"✅ API key saved: {test_key[:10]}...")
except Exception as e:
print(f"❌ Error saving key: {e}")
def main():
"""Main menu"""
while True:
print("\n=== FS25 Translator API Key Manager ===")
print("1. Check if key exists")
print("2. Set/Update key")
print("3. Delete key")
print("4. Exit")
choice = input("\nSelect option (1-4): ")
if choice == '1':
check_key()
elif choice == '2':
set_key()
elif choice == '3':
delete_key()
elif choice == '4':
break
else:
print("Invalid option")
if __name__ == "__main__":
main()