Created
April 6, 2022 23:53
-
-
Save lordsutch/79b509ec2b317641604762918cef1fd1 to your computer and use it in GitHub Desktop.
Randomly capitalize some text so you can be l33t on social media
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import argparse | |
import random | |
import sys | |
DEFAULT_PERCENTAGE = 40 | |
def randcaps(text: str, percentage: float = DEFAULT_PERCENTAGE) -> str: | |
return ''.join([x.swapcase() if random.uniform(0, 100) < percentage | |
else x for x in text]) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser( | |
description='Randomly capitalize standard input.') | |
parser.add_argument('-p', '--percentage', type=float, | |
default=DEFAULT_PERCENTAGE, | |
help='Percentage of letters to capitalize ' | |
f'(default: {DEFAULT_PERCENTAGE})') | |
parser.add_argument('text', type=str, default=None, nargs="*", | |
help="Text to capitalize instead of standard input.") | |
args = parser.parse_args() | |
if args.text: | |
print(randcaps(' '.join(args.text), percentage=args.percentage)) | |
else: | |
for line in sys.stdin: | |
print(randcaps(line.rstrip(), percentage=args.percentage)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment