Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AccountDetails:
- def __init__(self):
- self.error = ErrorHandling
- def get_email(self, length: int):
- """
- @length: Email length/Amount of characters in the email address.
- :returns: A email address (A fake one.)
- """
- pass
- def get_birthday(self):
- """
- :returns: birthday: A randomly generated birthday.
- get_birthday.year = the birthday year e.g (2019)
- get_birthday.month = the birthday month e.g (09)
- get_birthday.day = the birthday day e.g (23)
- """
- year = random.randrange(1990, 2000)
- month = random.randrange(1, 12)
- day = random.randrange(1, 27)
- return year, month, day
- def main(self):
- birthday = self.get_birthday()
- print(f"{birthday.year}, {birthday.month}, {birthday.day}")
- def get_username(self, length: int):
- """
- @length: Username length/Amount of characters in the Username (Must be between 1 to 12 characters).
- :returns: username | A randomly generated username.
- """
- # Uses our customly made errors and raises an error based on the length.
- try:
- if length < 1:
- error = self.error.TooShortError
- raise error
- elif length > 12:
- error = self.error.TooLongError
- raise error
- except error as e:
- length = 8
- print(e.message)
- finally:
- """We don't have to do any checks here
- because the length gets automatically set to a accepted length incase of any errors."""
- # Last digits is the ending of the username in order for the username to hopefully be available.
- last_digits = random.randrange(1, 123)
- username = ''.join(random.choices(string.ascii_lowercase, k=length)) + f"{last_digits}"
- # We have to check if the username is actually is 12 characters because we add X amount of digits at the end
- length_username = int(len(username))
- if length_username > 12:
- """We subtract 12 from the username length and then remove X amount of characters, X representing the
- remainder, if there is a remainder (which there only should be if there's more than 12 characters) """
- remainder = length_username - 12
- if remainder > 0:
- username = username[:-remainder]
- print(f"Generated username: {username}")
- return username
- def get_password(self, length: int):
- """
- @length: Password length/Amount of characters in the Password (Must be between 5 to 20 characters).
- :returns: password | A randomly generated password.
- """
- # Uses our customly made errors and raises an error based on the length.
- try:
- if length < 5:
- error = self.error.TooShortError
- raise error
- elif length > 20:
- error = self.error.TooLongError
- raise error
- except error as e:
- length = 12
- print(e.message)
- finally:
- """We don't have to do any checks here
- because the length gets automatically set to a accepted length incase of any errors."""
- password = ''.join(random.choices(string.ascii_uppercase + string.digits, k=length))
- print(f"Generated password: {password}")
- return password
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement