Skip to content

Commit a4fe1a9

Browse files
Update cli.py (#42)
1 parent 21e7cd7 commit a4fe1a9

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

caltechdata_api/cli.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,22 @@ def decrypt_token(encrypted_token, key):
6060

6161

6262
# Function to get or set token
63-
def get_or_set_token():
64-
63+
def get_or_set_token(production=True):
6564
key = load_or_generate_key()
66-
token_file = os.path.join(caltechdata_directory, "token.txt")
65+
66+
# Use different token files for production and test environments
67+
token_filename = "token.txt" if production else "token_test.txt"
68+
token_file = os.path.join(caltechdata_directory, token_filename)
69+
6770
try:
6871
with open(token_file, "rb") as f:
6972
encrypted_token = f.read()
7073
token = decrypt_token(encrypted_token, key)
7174
return token
7275
except FileNotFoundError:
7376
while True:
74-
token = input("Enter your CaltechDATA token: ").strip()
75-
confirm_token = input("Confirm your CaltechDATA token: ").strip()
77+
token = input(f"Enter your {'Production' if production else 'Test'} CaltechDATA token: ").strip()
78+
confirm_token = input(f"Confirm your {'Production' if production else 'Test'} CaltechDATA token: ").strip()
7679
if token == confirm_token:
7780
encrypted_token = encrypt_token(token, key)
7881
with open(token_file, "wb") as f:
@@ -403,7 +406,7 @@ def main():
403406

404407

405408
def create_record(production):
406-
token = get_or_set_token()
409+
token = get_or_set_token(production)
407410
print("Using CaltechDATA token:", token)
408411
while True:
409412
choice = get_user_input(
@@ -526,7 +529,7 @@ def print_upload_message(rec_id, production):
526529

527530
def edit_record(production):
528531
record_id = input("Enter the CaltechDATA record ID: ")
529-
token = get_or_set_token()
532+
token = get_or_set_token(production)
530533
file_name = download_file_by_id(record_id, token)
531534

532535
if file_name:

0 commit comments

Comments
 (0)