@@ -60,19 +60,22 @@ def decrypt_token(encrypted_token, key):
60
60
61
61
62
62
# Function to get or set token
63
- def get_or_set_token ():
64
-
63
+ def get_or_set_token (production = True ):
65
64
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
+
67
70
try :
68
71
with open (token_file , "rb" ) as f :
69
72
encrypted_token = f .read ()
70
73
token = decrypt_token (encrypted_token , key )
71
74
return token
72
75
except FileNotFoundError :
73
76
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 ()
76
79
if token == confirm_token :
77
80
encrypted_token = encrypt_token (token , key )
78
81
with open (token_file , "wb" ) as f :
@@ -403,7 +406,7 @@ def main():
403
406
404
407
405
408
def create_record (production ):
406
- token = get_or_set_token ()
409
+ token = get_or_set_token (production )
407
410
print ("Using CaltechDATA token:" , token )
408
411
while True :
409
412
choice = get_user_input (
@@ -526,7 +529,7 @@ def print_upload_message(rec_id, production):
526
529
527
530
def edit_record (production ):
528
531
record_id = input ("Enter the CaltechDATA record ID: " )
529
- token = get_or_set_token ()
532
+ token = get_or_set_token (production )
530
533
file_name = download_file_by_id (record_id , token )
531
534
532
535
if file_name :
0 commit comments