(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.
This commit is contained in:
parent
c55faa80f2
commit
106b08a507
1 changed files with 41 additions and 9 deletions
|
|
@ -1,14 +1,46 @@
|
|||
import secrets
|
||||
import string
|
||||
|
||||
def generate_random_subdomain(length=8):
|
||||
# Choose from alphanumeric characters
|
||||
def generate_random_string(prefix, length=8):
|
||||
"""Generates a random string with a given prefix."""
|
||||
alphabet = string.ascii_lowercase + string.digits
|
||||
# Generate a random subdomain using the chosen alphabet
|
||||
subdomain = ''.join(secrets.choice(alphabet) for _ in range(length))
|
||||
return f"psql-{subdomain}.rideaware.org"
|
||||
|
||||
# Example usage:
|
||||
random_url = generate_random_subdomain()
|
||||
print(random_url) # e.g., "a1b2c3d4.rideaware.org"
|
||||
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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue