This commit is contained in:
Wesley Neuhaus 2025-01-16 15:01:56 -05:00
commit 3eed0cd820

55
main.py Normal file
View File

@ -0,0 +1,55 @@
import secrets
import string
import json
def generate_api_key(length=32):
# Define the characters to be used in the key
characters = string.ascii_letters + string.digits
# Generate a secure random key
api_key = ''.join(secrets.choice(characters) for _ in range(length))
return api_key
def save_keys(keys, file_format='txt'):
filename = f"api_keys.{file_format}"
if file_format == 'txt':
with open(filename, 'w') as f:
for key in keys:
f.write(f"{key}\n")
else: # json format
with open(filename, 'w') as f:
json.dump({'api_keys': keys}, f, indent=2)
return filename
def main():
while True:
try:
num_keys = int(input("How many API keys do you want to generate? "))
keys = [generate_api_key() for _ in range(num_keys)]
# Print generated keys
print("\nGenerated API Keys:")
for i, key in enumerate(keys, 1):
print(f"{i}. {key}")
# Ask about saving to file
save_to_file = input("\nDo you want to save these keys to a file? (y/n): ").lower()
if save_to_file == 'y':
file_format = input("Choose format (txt/json): ").lower()
if file_format not in ['txt', 'json']:
print("Invalid format. Defaulting to txt")
file_format = 'txt'
filename = save_keys(keys, file_format)
print(f"\nKeys saved to {filename}")
# Ask about continuing
continue_gen = input("\nDo you want to generate more keys? (y/n): ").lower()
if continue_gen != 'y':
break
except ValueError:
print("Please enter a valid number")
continue
if __name__ == "__main__":
main()