string_generator/string_generator.py
Blake Ridgway 106b08a507 (feat): Generate random URLs for different server types
Allows users to select a server type (PostgreSQL, Redis, RabbitMQ,
Sandbox, Staging) and generates a random URL with a prefix
corresponding to the server type. The script loops until the user enters
'q' to quit or indicates they do not need another URL.

* Introduces interactive menu for server type selection.
* Implements URL generation based on chosen server prefix.
* Adds loop to generate multiple URLs until user quits.
* Handles invalid input and prompts the user again.
2025-04-19 01:36:51 +00:00

46 lines
1.4 KiB
Python

import secrets
import string
def generate_random_string(prefix, length=8):
"""Generates a random string with a given prefix."""
alphabet = string.ascii_lowercase + string.digits
random_string = ''.join(secrets.choice(alphabet) for _ in range(length))
return f"{prefix}-{random_string}.rideaware.org"
def main():
"""Prompts the user to select a server type and generates a random URL."""
while True:
print("Select a server type:")
print("1. PostgreSQL (psql)")
print("2. Redis (redis)")
print("3. RabbitMQ (rabbitmq)")
print("4. Sandbox Web Server (sandbox)")
print("5. Staging Web Server (staging)")
choice = input("Enter a number (1-5) to select a server type, or 'q' to quit: ")
if choice == '1':
prefix = "psql"
elif choice == '2':
prefix = "redis"
elif choice == '3':
prefix = "rabbitmq"
elif choice == '4':
prefix = "sandbox"
elif choice == '5':
prefix = "staging"
elif choice == 'q':
break
else:
print("Invalid choice. Please enter a number between 1 and 5.")
continue
random_url = generate_random_string(prefix)
print(f"Generated URL: {random_url}")
another = input("Generate do you need another URL? (y/n): ").lower()
if another != 'y':
break
if __name__ == "__main__":
main()